<!DOCTYPE html>
<html>
<head>
<title></title>
<style type="text/css">
.out{
background-color: blue;
}
.in-one{
width: 100px;
height: 100px;
background-color: red;
float: left;
}
.in-two{
width: 200px;
height: 100px;
background-color: yellow;
float: right;
}
</style>
</head>
<body>
<div class="out">
<div class="in-one"></div>
<div class="in-two"></div>
<div class="clear"></div>
</div>
</body>
</html>
结构大概如此,如果要清除浮动,可以设置一个同等级的空标签利用clear:both;也可以将class为out的元素设置为overflow:hidden或overflow:auto
经过查找,之所有overflow的操作可以清除元素,是因为设置overflow会触发BFC(Block Formatting Context),
那么问题是,为什么设置out为display:block没有作用呢?
设置为 overflow:hidden.
你可以直接在out 用伪类来清楚
clearfix:after{content:'.';display:block;clear:both;overflow:hidden;height:0;}
清除浮动有好多种,你这不是最好的一种,你可以总结一下,还有bfc的理解