The Rules of Margin Collapsehttps://www.joshwcomeau.com/css/rules-of-margin-collapse/
Definition: Elements' top and bottom margins are sometimes collapsed into a single margin that is equal to the larger of the two margins.
- Rule1: Only vertical margins collapse
- Rule2: Only adjacent elements collapse
- Rule3: The Bigger Margin Wins
- Rule4: Nesting doesn't prevent collapsing
- Because the parent's margin can absorb/transfer child's margin
- Unless .... (Rule 4.1)
There is another elements in-between the parent and child element
The parent element have a
height
set.The parent element have padding or border along the relevant edge.
And many more ... (see links above)
** Margins of floating and absolutely positioned elements never collapse.
Example: