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

HTML How to Make a Website Customizing Colors and Fonts Pick Fonts and Set Relative Units

Todd MacIntyre
Todd MacIntyre
12,248 Points

Why when I add a 'margin' to 'h1' does the 'background-color' from my 'body' appear above 'h1' in the buffer zone?

Shouldn't this buffer carry the value of the 'header' back-ground color? Why is this not the case?

3 Answers

Todd,

Here's a mnemonic I used to use to remember the order: MacBook Pro (MBP). Margin, Border, Padding.

Margin creates room around the element. It isn't a physical part of the element. If you want to have the color around the element as well you need to use padding. Hopefully this example will help: http://codepen.io/savant/pen/mVRzwW

Todd MacIntyre
Todd MacIntyre
12,248 Points

Yes, I recently found a nice diagram explaining this. Padding is inside the element's border and the margin is outside of its border: http://stackoverflow.com/questions/5958699/difference-between-margin-and-padding