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



I am stuck on a code challenge.

Currently, the width of the div with the class main is set to 400px, but the padding applied is adding an extra 40 pixels to its total width. Add a property that forces the padding into the width of the div.

2 Answers

I think what you need is the box-sizing property.

Try adding this to your CSS:

.main {
    -webkit-box-sizing: border-box; /* I am not sure if your code challenge requires vendor prefixes or not, but this one is for chrome and safari */
    -moz-box-sizing: border-box; /* this prefix is for FireFox*/
    box-sizing: border-box;

You can read more about this CSS3 property here: http://www.w3schools.com/cssref/css3_pr_box-sizing.asp

Aleem Mohamed
Aleem Mohamed
Courses Plus Student 7,011 Points

Erik Krieg, good answer. I believe this is what the code challenge is looking for. From what I understood the border-box property is just doing the math that was done in the answer provided by Jason Montoya.

Jason Montoya
Jason Montoya
6,550 Points


Padding adds pixels on the inside of an element. So if you add 20px of padding, you would have to subtract 20px from the left AND right side to give you your new 400px width.

400 - 20 - 20 = 360px (if you're are trying to keep outer element same width i.e. your class main).

/* 400px width total */

     padding: 20px;

Hope this helps.