外边距(垂直外边距的重叠)
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<style type="text/css">
.bxo1 {
width: 100px;
height: 100px;
background-color: red;
margin-bottom: 100px;
}
.box2 {
width: 100px;
height: 100px;
background-color: green;
margin-top: 100px;
}
.box3 {
width: 200px;
height: 200px;
background-color: yellow;
padding-top: 100px;
}
.box4 {
width: 100px;
height: 100px;
background-color: green;
margin-top: 100px;
}
</style>
</head>
<body>
<div class="box3">
<div class="box4"></div>
</div>
<div class="box1"></div>
<div class="box2"></div>
</body>
</html>
![请添加图片描述](https://i-blog.csdnimg.cn/blog_migrate/98bcbea18aca8f2a1918ddb2b0ef1688.png)
垂直外边距的重叠
- 在网页中相邻的垂直方向的外边距会发生外边距的重叠
- 所谓的外边距重叠指的是兄弟元素之间的相邻外边距会取最大值而不是取和
- 如果父子元素的垂直外边距相邻了,则子元素的外边距会设置给父元素