您的位置:首页 > Web前端 > CSS

[转]在css+div里面实现div的底对齐

2017-04-13 10:25 281 查看
1、之前代码:

<style>
#parent{
width:300px;
height:300px;
background:gray;
}
#i_want_to_be_bottom{
width:100px;
height:30px;
background:red;
}
</style>
<div id="parent">
<div id="i_want_to_be_bottom"></div>
</div>

 



修改后代码:

<style>
#parent{
width:300px;
height:300px;
background:gray;
position:relative;
}
#i_want_to_be_bottom{
width:100px;
height:30px;
background:red;
position:absolute;
bottom:0px;
}
</style>
<div id="parent">
<div id="i_want_to_be_bottom"></div>
</div>

 



 变动点提示


#parent{

....

postion:relative;


....

}

#i_want_to_be_bottom{

....

position:absolute;


bottom:0px;


....





当然,你也可以设置子div的margin选项达到底对齐的目的,但是如果父div的高度是可变的时候,这样做就不行了。所以,达到子div底对齐的万能办法是使用如上所述办法,当然,有的时候,你可以使用子div的right:0px来达到右对齐的目的。

本例来源:
http://blog.sina.com.cn/s/blog_4c4a58ca01000bed.html





大小: 2.7 KB





大小: 2.1 KB

查看图片附件
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: