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 Basics (2014) The Box Model Margins

Can an element a be a content area for a box, as well as a box itself?

.

2 Answers

The content area is the inner width by inner height of an element.

.box {
  box-sizing: content-box:
  width: 100px;
  height: 100px;
  padding: 20px;
  border: 5px dash blue;
}

The element with the class .box would have a content area of 100px by 100px. This picture visualizes the concept. So yes it should be the case.

.

If not explicitly defined like in the above example, yes. The browser and many other markup based graphic frameworks, like WPF for windows apps, go down the markup tree, in the case of the web your html, try to get the space each child needs and then adapt the parents size accordingly.

.

Do ALL elements (including inline and block) in HTML come with padding and margin by default?

That depends on your user agents style sheet, which you can override with a css reset.

Hmm okay. So would you say that all elements are originally just their content box, except once padding and margin are applied to them?

If box-sizing is set to content-box, that is correct.