<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>去除浮动</title>
<style type="text/css">
*{
margin: 0;
padding: 0;
}
.box{
width: 300px;
background-color: red;
margin: 20px auto;
padding: 20px;
}
.box div{
width: 80px;
height: 80px;
float: left;
}
.clearfloat::after{
content: '';
clear: both;
display: block;
}
</style>
</head>
<body>
<div class="box">
<div ></div>
<div ></div>
<div ></div>
</div>
</body>
</html>
1:给父元素加上display: flex
2:给父元素加上overflow: auto||hidden
3:给父元素加上名为clearfloat的class
以上三种方法均可达到消除浮动的效果