I'm creating a footer for my page, and giving each paragraph a margin of 2rem
. This margin should collapse to create 2rem
gap in between.
The problem is, the margin seeps to be propagating to the parent div element, resulting in no spacing at the top and bottom of the footer (look at the black background in the first example). Why is this happening?
So there's no spacing, ok, probably something to do margin collapsing. So I then add (as seen in the second example) a 2rem
padding to the footer div. But now the spacing is including the margin and padding, resulting in a total of 4rem
! How do I get the intended 2rem
spacing?
Example 1:
<div class="a">
<p>
First paragraph
</p>
<p>
Second paragraph
</p>
</div>
Example 2:
<div class="b">
<p>
First paragraph
</p>
<p>
Second paragraph
</p>
</div>