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

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

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