div定位理解

对div定位的理解

 

positon有4个属性:static relative absolute fixed.

默认的时候是static即静止定位,是按照元素在(x)html出现的顺序依次分配位置,static是不受top right left bottom影响的.

当父层a的position设为relative(相对定位) 子层b的position设为absolute(绝对定位)时,b的偏移是相对于父层a来定位,例如top:10px的偏移量就使b的顶部和a的顶部有10px的距离.但是如果a没有设置relative 而b设为absolute,b的定位就是相对于浏览器进行,此时top:10px会使b出现在离浏览器上方10px的地方.

 

-----------------------div居底部-----------------

·思路及要点:
父div的位置设置成相对的,即“position: relative;”。
而子div的位置设置成绝对的,并且下边缘设为0,即“position: absolute; bottom: 0;”。
 
 · 代码:
 
<head>
    <title>子div在父div中置底</title>
    <style type="text/css">
        .father { width: 500px; height: 600px; position: relative; background-color: AliceBlue; }
        .child { width: 400px; height: 100px; position: absolute; bottom: 0; background-color: AntiqueWhite; }
    </style>
</head>
<body>
    <div class="father">
        <div class="child">
        </div>
    </div>
</body>

 

</html>

 --------------------------------------------------------

一、水平居中

.hor_center {  

        margin: 0 auto;  

}  

 

二、水平垂直居中

.content {  

      width: 360px;  

      height: 240px;  

}  

.ver_hor_center {  

      position: absolute;  

      top: 50%;  

      left: 50%;  

      width:360px;

      height:240px;

      margin-left: -180px; /*要居中的div的宽度的一半*/  

      margin-top: -120px; /*要居中的div的高度的一半*/  

}  

 

三、div置于底部(footer)

.bottom_footer {  

       position: fixed; /*or前面的是absolute就可以用*/  

       bottom: 0px;  

}  

 

 

 

http://www.wibibi.com/info.php?tid=138

 

http://blog.sina.com.cn/s/blog_92d6237201016jhs.html

 

http://blog.csdn.net/sykent/article/details/7791284

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值