导航首页 » 技术教程 » 一个老外弄的Clearing floats(清除浮动的方法)
全站头部文字 我要出现在这里
一个老外弄的Clearing floats(清除浮动的方法) 8 2024-10-22   

我常用的都是clear:both;方法,如


<div style="clear:both">
<div style="float:left"></div>
<div style="float:right"></div>
</div>



今在PlanABC看到另外这种方法,特些记录下来。

div.container {
border: 1px solid #000000;
}

div.left {
width: 45%;
float: left;
}

div.right {
width: 45%;
float: right;
}


层套关系:container的div包含left和right

最简单合理的清除浮动的方法(红色粗体部分):

div.container {
border: 1px solid #000000;
overflow: hidden;
width: 100%;
}

兼容情况:IE6 IE7 FF MacIE等

来源地址:http://www.quirksmode.org/css/clearing.html

PS:不过在使用的过程貌似还有小的BUG,淘宝的小马曾碰到过,具体的症状是,IE6中层套清除浮动的div,导致部分链接无法点击。


!!!站长长期在线接!!!

网站、小程序:定制开发/二次开发/仿制开发等

各种疑难杂症解决/定制接口/定制采集等

站长微信:lxwl520520

站长QQ:1737366103