<!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 {
width: 200px;
height: 200px;
border: 1px solid #ccc;
}
.son {
width: 100px;
height: 100px;
background-color: #ccc;
}
.brother {
width: 100px;
height: 100px;
background-color: pink;
margin: 100px;
}
.outer {
overflow: hidden;
}
</style>
</head>
<body>
<p>父子外边距合并</p>
<div>解决办法</div>
<ul>
<li>父元素设置内边距,边框</li>
<li>父元素设置overflow: hidden</li>
<li>子元素设置浮动</li>
</ul>
<div class="father">
<div class="son">i am son</div>
</div>
<p>兄弟外边距合并</p>
<div>解决办法</div>
<ul>
<li>1. 给这两个兄弟元素都添加一个父元素,并且设置父元素overflow:hidden</li>
<li>2. 给其中一个元素添加定位position:absolute</li>
</ul>
<!-- <div class="outer"><div class="brother1 brother">i am brother1</div></div>
<div class="outer"><div class="brother2 brother">i am brother2</div></div> -->
<div class="brother brother1">i am brother1</div>
<div class="brother brother2">i am brother2</div>
</body>
</html>
完善中。。。