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

Vertical Margins confuse me

Hello,

I was watching the 3rd video in the "CSS Layout Basics" course about Vertical Margins, and why they collapse.

Now for the most part I got the idea: When 2 margins of block-level elements touch each other, they collapse to the larger margin between them.

Here's the question: IF :

body {
  margin: 0px;
}

how can it collapse with the "h1" element and furthermore why guil says that the margin on the h1 "pushes down" the header

Thanks for all replies in advance

2 Answers

Steven Parker
Steven Parker
243,656 Points

There are two kinds of margin collapse: between adjacent siblings, and on an edge shared by a parent and child. Since the code shown has no rules for h1 or heading, I'd guess your question refers to the behavior of the default margins in the second type.

You might find these references helpful: Mastering margin collapsing and What You Should Know About Collapsing Margins.

Thank you steve, your're awesome!