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) Basic Layout Width and Height Properties

James Estrada
James Estrada
Full Stack JavaScript Techdegree Student 25,862 Points

What's Included in the Box?

Guil Hernandez mentions: "Keep in mind that when a width or height is defined on a element, we're not exactly defining the entire area of the box, meaning the content, padding and borders. We're actually just defining the width for the content area itself".

What about margins? Aren't they included in the area of the box?

1 Answer

Steven Parker
Steven Parker
218,694 Points

No, margins are never included in box dimensions. However, padding and borders might be.

There's a setting called "box-sizing" that allows you to change the box model a bit. By default, it is "content-box", which is the situation described above where the dimensions include only the content area.

But you can set it to "border-box", and then the dimensions will include content, padding, and borders.

But, alas, there is no "margin-box" setting.