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

Juan David Hernandez
Juan David Hernandez
7,415 Points

Positive and negative margins

I wondering what happen if I use something like:

.div1 { margin-bottom: 100px; }

.div2{ margin-top: -50px; }

In that case the div1 is going to override the div2's margin-top?

1 Answer

Martin Ellis
Martin Ellis
6,724 Points

Hi Juan,

.div-2's -50px margin value would be subtracted from the 100px margin of .div-1 leaving you with 50px of margin spacing between the two divs. If .div-1 had 200px of bottom margin then the -50px would be taken from that, leaving you with 150px margin spacing between the two divs etc..

Hope this helped :)