Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

CSS CSS Basics (2014) The Box Model Margins

Sunshine Khawaja
Sunshine Khawaja
1,845 Points

H2 margin decreases the space b/w the paragraph below. So far we've been using margin to increase space b/w elements.

In this video we're adding a margin-bottom of .5em to the H2 element. This actually decreases the space between the H2 and the paragraph below. So far we have just used margin to push away other elements, so can someone explain why this actually does the opposite in this instance? Is it because it's an H2 and automatically has more margin around it because it's a block element? Also, would adding margin-top to the p element do the same thing?

Aaron HARPT
Aaron HARPT
19,845 Points

It is because 0.5em for margin is less than the default margin which is around 0.85em so a value of 0.5em would be a slight negative making the elements closer to each other. Also, margin-top on the p element would do the same thing.

Hope that helps.

1 Answer

Sunshine Khawaja
Sunshine Khawaja
1,845 Points

That's the exact answer I was looking for. I didn't know what the default margin was so thanks so much!