CSS布局+static relative fixed absolute

在CSS中关于定位的内容是:
position:relative | absolute | static | fixed
    static(静态) 没有特别的设定,遵循基本的定位规定,不能通过z-index进行层次分级,这是默认值。 
    relative(相对定位) 对象不可层叠、不脱离文档流,参考自身静态位置通过 top,bottom,left,right 定位,并且可以通过z-index进行层次分级。 
     absolute(绝对定位) 脱离文档流,通过 top,bottom,left,right 定位。选取其最近一个最有定位设置的父级对象进行绝对定位,如果对象的父级没有设置定位属性,absolute元素将以body坐标原点进行定位,可以通过z-index进行层次分级。 
    fixed(固定定位) 这里所固定的参照对像是  可视窗口 而并非是body或是父级元素,其总是固定在浏览器窗口的某个位置,并且不受滚动的影响,是绝对的坐标定位。可通过z-index进行层次分级。 
 : 
CSS中定位的层叠分级:  z-index: auto | namber; 

auto 
遵从其父对象的定位 
namber   无单位的整数值。可为负数,默认值为0,越大越靠上,值大的元素会覆盖住值小的元素。
 
<html><head>
<style type="text/css">
body{margin:0px;padding:0px;line-height:100%;}
div
{
  background-color:rgb(159, 206, 159);
  width:95px;
  height:95px;
  margin: 0px 0px 1px 1px;
  padding:0px;
  /*display:inline-block;*/
  letter-spacing:1px;
  
  /* only for ie*/
  *display:inline;
  *zoom:1;
  
  border:1px solid #ffffff;
  border-radius:5px;
  -moz-border-radius:5px; /* Old Firefox */
  opacity:1;
  text-align:center;
  color:white;
}
#main{width:400px;height:300px;}
</style>
</head>

<body>
<div id="main" style="
    position: relative;
    margin: 50px;
    padding: 80px;
">
<div id="div1" style="
    position: absolute;  
    left: 83px;  
    top: 0px;
    background-color: rgb(199, 219, 50);
">div1 absolute</div>
<div id="div2" style="
    position: absolute;  left: 0px;  
    top: 90px;
    background-color: rgb(1, 214, 35);
  z-index:10;
">div2 absolute z-index<br/>:10</div>
<div id="div3" style="
    position: relative;  left: 0px;  
    top: 0px;
    background-color: rgb(23, 178, 238);
  z-index:11
">div3 relative z-index:11</div>
<div id="div3" style="
    position: relative;  left: 0px;  
    top: 0px;
    background-color: rgb(23, 178, 238);
  z-index:0;
">div4 relative z-index:0</div>
<div id="div5" style="
    position: fixed;  left: 10px;  
    top: 10px;
    background-color: rgb(229, 122, 238);
">div5 fixed</div>
</div>

</body></html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值