以前给你们介绍两种浮动闭合的办法CSS清除浮动 万能float闭合,得知不少同窗都在使用下面的骨灰级解决办法:css
.clear{clear:both;height:0;overflow:hidden;}
上诉办法是在须要清除浮动的地方加个div.clear或者br.clear,咱们知道这样能解决基本清浮动问题。html
可是这种方法的最大缺陷就是改变了html结构,虽然只是加个div。dom
.clearfix:after{content:".";display:block;height:0;clear:both;visibility:hidden} .clearfix{*+height:1%;}
用法很简单,在浮动元素的父云素上添加class=”demo clearfix”。测试
你会发现这个办法也有个弊端,但的确是小问题。改变css写法就ok了:spa
.demo:after,.demo2:after{content:".";display:block;height:0;clear:both;visibility:hidden} .demo,.demo2{*+height:1%;}
以上写法就避免了改变html结构,直接用css解决了。code
.clearfix{overflow:auto;_height:1%}
这种办法是我看国外的一篇文章获得的方案,测试了,百试不爽,真的很简单,很给力。喜欢的同窗也能够试试这个办法。htm
这种方法是端友radom提供的,测试经过:blog
.clearfix{overflow:hidden;_zoom:1;}
感谢radom提供的这种方法!!get