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

css 清除浮动方法

2011-11-28 11:34 651 查看
1.使用空标签清除浮动
<style type="text/css">
.clear{clear:both;font-size:0px;height:0px;line-height:0px;overflow:hidden;}
</style>
<div style="background:blue;">
<div style="float:left;width:400px;height:300px;background:red;">red</div>
<div style="float:left;width:400px;height:300px;background:gray">ball</div>
<div class="clear"></div>
</div>
2.使用after伪对象清除浮动
<style type="text/css">
.ft_clear:after{visibility:hidden;display:block;font-size:0;content:" ";clear:both;height:0;}
.ft_clear {zoom:1;}/*IE6*/
</style>
<div style="background:blue;" class="ft_clear">
<div style="float:left;width:400px;height:300px;background:red;">red</div>
<div style="float:left;width:400px;height:300px;background:gray">ball</div>
</div>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: