传统方案
在需要清除浮动的地方加个div.clear或者br.clear
.clear{
clear: both;
height: 0;
overflow: hidden;
}
缺点:
改变了html的结构,添加了个div
最优浮动解决方案
.clearfix:after {
content: ".";
display: block;
height: 0;
clear: both;
visibility: hidden;
}
.clearfix {
*+height:1%;
}
or
.clearfix:after {
visibility: hidden;
display: block;
content: " ";
clear: both;
}
.clearfix {
zoom:1;
}
最暴力的浮动闭合方式
.clearfix {
overflow: auto;
_height:1%;
}