当给多个盒子浮动实现一行多个,且不止一行时,只给第一个或前n-1个下边距会导致下面盒子塌陷且错乱
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.father {
height: 220px;
width: 220px;
margin: 100PX auto;
background-color: #f00;
}
.father .son1 {
float: left;
height: 100px;
width: 100px;
background-color: #0f0;
margin-bottom: 10px;
}
.father .son2 {
float: left;
height: 100px;
width: 100px;
background-color: #00f;
}
.father .son3 {
float: left;
height: 100px;
width: 100px;
background-color: #f0f;
}
.father .son4 {
float: left;
height: 100px;
width: 100px;
background-color: #19f;
}
.father div {
margin-right: 10px;
}
</style>
</head>
<body>
<div class="father">
<div class="son1"></div>
<div class="son2"></div>
<div class="son3"></div>
<div class="son4"></div>
</div>
</body>
</html>
如图:
![](https://img-blog.csdnimg.cn/img_convert/ee8a7096e85a00eb1f3a10dccbb2b5e0.jpeg)
这时候必须给上面所有的盒子给下边距就会正常
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.father {
height: 220px;
width: 220px;
margin: 100PX auto;
background-color: #f00;
}
.father .son1 {
float: left;
height: 100px;
width: 100px;
background-color: #0f0;
margin-bottom: 10px;
}
.father .son2 {
float: left;
height: 100px;
width: 100px;
background-color: #00f;
margin-bottom: 10px;
}
.father .son3 {
float: left;
height: 100px;
width: 100px;
background-color: #f0f;
}
.father .son4 {
float: left;
height: 100px;
width: 100px;
background-color: #19f;
}
.father div {
margin-right: 10px;
}
</style>
</head>
<body>
<div class="father">
<div class="son1"></div>
<div class="son2"></div>
<div class="son3"></div>
<div class="son4"></div>
</div>
</body>
</html>
![](https://img-blog.csdnimg.cn/img_convert/5708d2834856e380ee6aa4b87d781cb9.jpeg)