清除浮动的方法
<style>
.box {
overflow: hidden;
width: 500px;
margin: 50px auto;
border: 5px solid red;
}
.left {
width: 200px;
float: left;
height: 200px;
background-color: #ccc;
}
</style>
<style>
.clearfix::after {
content: '';
display: block;
clear: both;
}
</style>
<body>
<div class="box clearfix">
<div class="left">left</div>
</div>
</body>
.box {
float: left;
width: 500px;
margin: 50px auto;
border: 5px solid red;
}
.left {
width: 200px;
float: left;
height: 200px;
background-color: #ccc;
}

在父级浮动元素的最后面加上class名字为clear的div也可以清除浮动
<style>
.clear {
clear: both;
}
</style>
<body>
<div class="box clearfix">
<div class="left">left</div>
<div class="clear"></div>
</div>
</body>