float 清除浮动的三种方式

来源:互联网 发布:乐乎网页版 编辑:程序博客网 时间:2024/05/12 00:07

 

1.使用伪元素清除浮动
.box::after{ content: " "; clear: both; display: block;}
.left,.right{ width:100px; height: 100px; background:#388bff; float: left;}
<div class="box">
<div class="left"></div>
<div class="right"></div>
</div>
2.使用overflow:hidden清除浮动
.box{ overflow: hidden;} //overflow:auto也是可以的
.left,.right{ width:100px; height: 100px; background:#388bff; float: left;}
<div class="box">
<div class="left"></div>

<div class="right"></div>
</div>
3.使用空div
.clear{ clear:both; }
<div class=clear></div>


0 0
原创粉丝点击