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

abdirahman liban
PLUS
abdirahman liban
Courses Plus Student 2,163 Points

about vertical margin collapse

why i have to put top margin of (h1) =0 instead i can put padding = 1em 0; for the (h1)?

2 Answers

abdirahman

Adding padding to your h1 element will not solve your vertical margin collapse issue, because padding will be added within the h1 element and therefore will not affect the margins.

See my quick screencast, that i created with Jing, that tries to explain it for you.

http://screencast.com/t/VzEbPFeu

Hope this helps explain it for you.

Morten Larsen
Morten Larsen
12,275 Points

Great reply. Thank you very much. Helped me a ton.

Keith Carrillo
Keith Carrillo
6,909 Points

Could you tell me why does a border wrap around margin after they collapse, instead of a the margin sticking to the outside of a border..