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

abdirahman liban
abdirahman liban
Pro 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


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.


Hope this helps explain it for you.

Morten Larsen
Morten Larsen
12,263 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..