Show a margins collapse here.
.ct1{
background: red;
margin:40px;
border:1px solid;width:100%;
}
.ct2{
background: pink;
margin:40px;
border:1px solid;width:100%;
}
<div class="ctbox">
<div class="ct1">first</div>
<div class="ct2">second</div>
</div>
There will be a margins collapse between two divs ct1 and ct2,the distance between them is not 40px+40px = 80px ,instead of 40px.
Now i add a css statement display:inline-block; in ct1 or ct2,the distance between them will become 80px,the margins collapse dispear.Why display:inline-block; can prevent margins collapse ?
From this rule, Collapsing Margins
inline-block boxes do not collapse (not even with their in-flow children)....
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With