程序员的出路

alex.w的Blog

导航

Css实现DIV绝对定位

Posted on 2008-04-08 21:48  alex.w  阅读(1681)  评论(1)    收藏  举报
<style type="text/css">
.box1 
{border:1px #cccccc solid;  width:500px; height:600px;}
.box2 
{border-top:1px #cccccc solid; border-bottom:0; background:#f2f6fb; width:500px; height:22px;}
</style>
<div class="box1">
<div class="box2"></div>
</div>

底部对齐的代码:

<style type="text/css">
.box1 
{border:1px #cccccc solid;  width:500px; height:600px;position:relative;}
.box2 
{border-top:1px #cccccc solid; background:#f2f6fb; width:498px; height:22px; position:absolute; bottom:0;}
</style>
<div class="box1">
<div class="box2"></div>
</div>

//父DIV一定要设置position:relative才能让子DIV实现对父DIV的绝对定位