css 浮动闭合

在父元素上添加class即可
最优浮动闭合方案:

.clearfix{
zoom:1;
}      //zoom针对ie6和ie7  触发其hasLayout

   //以下针对除ie6和ie7之外的其他浏览器
.clearfix:after {
content:".";
display:block;
height:0;
clear:both;
visibility:hidden;
}

<div class="clearfix">

  <div style="float:left;"></div>

  <div style="float:left;"></div>

</div>

下面2篇文章讲了一些关于闭合浮动的内容:http://www.javascript100.com/?p=235

http://homepage.yesky.com/16/2404516.shtml

另外两种清楚浮动的方式

1.用在父元素

.clear-box {
overflow: auto;
zoom: 1;
}  //ie6下容易出现滚动条( 当元素用width和height的时候容易出现滚动条,但是不确定。。。。。。)

2.加在父元素所包含的带有浮动子元素的后面

<div style="clear:both"></div>

原文地址:https://www.cnblogs.com/mabelstyle/p/2965614.html