1.给父级元素添加clearfix名,使用after伪类清除浮动
.clearfix:after{
content: "";
display: block;
height: 0;
clear: both;
visibility: hidden;
}
.clearfix {
/* 触发 hasLayout */
zoom: 1;
}
2.在浮动元素后添加一个元素
<div class="clear"></div>
.clear{
clear:both;
}
网友评论