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
Benjamin Hedgepeth
5,672 PointsMeasuring padding and margins using background-color?
Is this common practice? Such as measuring the space between a h1 and h2 in a logo by highlighting one of those elements with a different color?
1 Answer
Jonathan Grieve
Treehouse Moderator 91,254 PointsPadding and margins are both layers in the box model.
The box model of any element, including for example H1 and H2 each take up a default amount of space. They have default, content, margin , border and padding values.
The Box Model consists of the following
Content
Padding
Border
Margin
The combined widths of each of these in terms of width and height determines how much space this element takes up on the page.
For example
.box {
width: 50px;
border: solid red 3px;
height: 50px;
padding: 20px;
margin: 10px;
}
This element has many pixel unit values attached to it.
The actual size of this element's content is 50px in width and height. A perfect square.
But it has a border of 3px on each side increading the space it takes up.
The padding pushes the content against the border increasing the space it takes up against the border by 20px on each side.
And finally the margin pushes the space between the border and the other content by 10px on each side. This makes a total size of 83px on all sides in terms of the total space it takes up.
Hope this helps :)