Welcome to the Treehouse Community
Looking to learn something new?
Margin collapsing and borders
What does applying a border to a parent container do to prevent the margin of a first child element from collapsing?
From a box model perspective, a border is not needed to apply a margin between sibling elements. Is it just a means of creating a specific context with a parent container specific to the first child element?
Steven Parker221,070 Points
The rule for parent-child margin collapse is that the margins must overlap with no separation to collapse. Separation would include border, padding, inline elements, and even specific dimensioning. So applying a border to the parent separates the parent margin from the child margin and will prevent margin collapse.
The rule for adjacent siblings is different, margins are always collapsed. Either or both of them may have a border and it will make no difference. But when you think about it, borders on siblings don't create separation, nor would padding or dimensioning.