3.23课·········格式与布局

一、positionfixed

  锁定位置(相对于浏览器的位置),例如有些网站的右下角的弹出窗口。

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style type="text/css">
#a
{
    border:5px solid #00F;
    width:100px;
    height:100px;
    margin:10px;
    background-color:#0F3;
    left:50px;
    bottom:20px;
    position:fixed;    
}
</style>
</head>
<body>
<div id="a">广告招商</div>

显示如下:

二、positionabsolute

  1.外层没有position:absolute(或relative);那么div相对于浏览器定位,如下图中b(距离浏览器右边框为50像素,距离下边框为20像素)。

  2.外层有position:absolute(或relative);那么div相对于外层边框定位,如下图中bb(距离d的右边框50像素,距离d的下边框为20像素)。

示例:

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>

<style type="text/css">
.b
{
    border:5px solid #00F;
    width:100px;
    height:100px;
    margin:10px;
    background-color:#0F3;
    right:50px;
    bottom:20px;    
    position:absolute;    
    }
.c
{
    border:2px solid red;
    width:400px;
    height:200px;
}
.d
{
    border:2px solid red;
    width:400px;
    height:200px;
    position:absolute;
}
</style>
</head>
<body>
<div class="c">c<div class="b">b</div></div>
<div class="d">d<div class="b">bb</div></div> 
</body>
</html>

三、positionrelative

  相对位置。

  如下图,相对于把此div包含住的div的某个位置进行固定。如果外层没有包含他的,那就相对于浏览器进行相对位置的固定。

示例:

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style type="text/css">
#a
{
    border:5px solid #00F;
    width:100px;
    height:100px;
    margin:10px;
    background-color:#0F3;    
    position:fixed;    
}
.aa
{
    border:5px solid #00F;
    width:100px;
    height:100px;
    margin:10px;
    background-color:#0F3;
    left:50px;
    top:50px;
    position:relative;
}    
</style>
</head>
<body>
<div id="a">a</div>
<div class="aa">aa</div> 
</body>
</html>

四、分层(z-index

  z轴方向分层,可以理解为分成一摞纸,层数越高越靠上。

  在上面relative的示例中,我们看到了aa遮住了a,这是因为后写代码的显示级别越靠前,那么在不改变代码顺序的情况下如何让a盖住aa?如下:

示例:

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style type="text/css">
#a
{
    border:5px solid #00F;
    width:100px;
    height:100px;
    margin:10px;
    background-color:#0F3;    
    position:fixed;
    z-index:2;       /* 这里做一下修改,默认情况下,都是第一层    */
}
.aa
{
    border:5px solid #00F;
    width:100px;
    height:100px;
    margin:10px;
    background-color:#0F3;
    left:50px;
    top:50px;
    position:relative;
}
</style>
</head>
<body>
<div id="a">a</div>
<div class="aa">aa</div> 
</body>
</html>

五、floatleftright

Leftright时不用给他规定位置(lefttop),直接相对于浏览器。若外部被包裹,相对于外部div的除去一行的位置的左上或右上显示。

  overflow:hidden;    //超出部分隐藏;scroll,显示出滚动条;

  <div style="clear:both"></div>   //截断流

附:cursor:pointer    鼠标指到上面时的形状,pointer是 

     &copy                  版权符号©

半透明效果:

  <div class="box">透明区域<div>

在样式表中的代码为:

.box

{

opacity:0.5; -moz-opacity:0.5 ; filter:alpha(opacity=50)

}

原文地址:https://www.cnblogs.com/xinghun/p/5319689.html