Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

CSS CSS Basics (2014) The Box Model Padding

David Regel
seal-mask
.a{fill-rule:evenodd;}techdegree
David Regel
Full Stack JavaScript Techdegree Student 5,504 Points

What is the basis of our 18% and 24% padding we use in this course?

I know that the width of the container is the basis which our percent-value for padding is based on. Which element is the container that the padding-value is based on in this video? Is it the body-element? When we use 18% as the top and bottom value for our padding, why is there more space on top than at the bottom?

2 Answers

Steven Parker
Steven Parker
218,653 Points

The percentage values are still based on the parent (container) element. which in this case is the div with class "primary-content".

Paragraphs (p) and headings {h2) both have margins that add to the padding, making it appear that the padding sizes are not equal (when they are).

You can examine this using the browser's developer tools, or you could add another container with a visible border just inside the one with the padding to show the content boundaries.

Steven Parker
Steven Parker
218,653 Points

It's the parent element because it surrounds the element in question. It's placement in the body is just a coincidence.

Kathya Sarria
Kathya Sarria
945 Points

I did not quite understand the padding based on the width. What is the width of that div? Can you go further in this logic. Thanks!

Steven Parker
Steven Parker
218,653 Points

It's not unique to padding. Any percentage unit is relative to the width of the parent element.