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

Saqib Ishfaq
Saqib Ishfaq
13,912 Points

why can't i just set the margin:0; instead of adding padding in header then setting the margin to 0 again?

h1{ margin:0; }

.main-header { background:#3acec2; } thats works just fine and the i can also add adding to .main-header! point is there will be no collapsing issue then! or m i corrct to do this?

2 Answers

there will be no collapsing issue as the padding & margin areas are two different areas, so their order will not matter, you can set the padding first then reset the margin, or reset margin then set the padding. it's gonna be the same

Matt Brock
Matt Brock
28,305 Points

Hey Saqib, could you add some more code from the example? It may be helpful to see what elements you're talking about. Thanks!