Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

CSS CSS Layout Basics Getting Started with CSS Layout Why Vertical Margins Collapse

Vertical Margin Collapsing

Is someone able to make me a summarize about Vertical Margin Collapsing. Please tell how it happen and why does this happen. Please be clear because I am mixed up! Thanks in advance.

1 Answer

Steven Parker
Steven Parker
231,236 Points

Margins are combined ("collapsed") by the browser so that the total margin is the same as single largest one. This happens in 3 cases:

  1. The bottom margin of one element is combined with the top margin of the next (sibling) element
  2. The top margins (or bottoms) of a parent and child element are combined
  3. The top and bottom margins of a single element with no contents are combined

That's the short summary. For more details, see the MDN page on Mastering margin collapsing.