首先,这里是HTML代码:
<div class="first">
<div class="second">
<div class="third">
Hello, margin collapsing!
</div>
</div>
</div>
下面是CSS代码:
.first {
background-color: red;
padding: 20px;
}
.second {
background-color: green;
margin-bottom: -20px;
}
.third {
background-color: yellow;
margin-bottom: 20px;
}
在最终布局中,第三个 div 看起来好像没有底部边距。我知道这一定是第二个 div 底部边距为负的影响,但我不明白它是如何起作用的。你能否给出一个解释?