View on GitHub

notes

A collection of my TIL notes and commonplace book entries.

Margin Collapsing

Cases when margin collapsing occurs:

  1. Margins of adjacent siblings are collapsed (exception: lower sibling needs to be cleared past floats).
  2. If there is no content separating the margin-top of a parent from that of one of its decendants, collapsed margin ends up outside the parent. The same goes for margin-bottom.
  3. If there is no content in a block to separate its margin-top from its margin-bottom then the top and bottom margins collapse.

Source: https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Box_Model/Mastering_margin_collapsing