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

Width, Height and Overflow Properties Code Challenge

Can anyone help, I'm not understanding the following question

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.

Here the link to the code challenge

http://teamtreehouse.com/library/width-height-and-overflow-properties

15 Answers

Yeyy it worked! I was so annoyed! Thanks Guil ^^,

Guil Hernandez
Guil Hernandez
Treehouse Teacher

No problem, Carlos. Technically, your answer was correct. Border-box is just more of a commonly used "catch-all" fix for box model issues.

Hey Richard,

I would love to help you out with this challenge. I actually was doing this challenge last night and this same task was giving me trouble too. What a coincidence. What you will need to do to force the padding into the width of the div is to first select the div in your CSS. Like this:

.main{}

Next you are going to add a special propriety "box-sizing" and add "border-box" so it will end up looking something like this:

.main{box-sizing: border-box;}

Good luck and hope this helps

Dan

Guil Hernandez
STAFF
Guil Hernandez
Treehouse Teacher

Hi Richard Mockford,

The Code Challenge question is asking you to use a certain property that subtracts any borders or padding from the total box width.

I start talking about it around the 8min mark in this video.

I also wrote an article on this for the Treehouse Blog :)

Guil,

Since the challenge is only asking specifically to include the padding, I am wondering why the following doesn't work?

.main {box-sizing: padding-box;}
Guil Hernandez
Guil Hernandez
Treehouse Teacher

Michael Tupper,

Excellent point. padding-box is technically correct if it's specifically for the padding area. box-sizing is more of a catchall and more commonly used, but I can see how the question is misleading. I'll reword the question.

Thanks!

I know this is an old forum post, but for Michael Lesniak, just typing,

a {
  display: inline-block;
  width: 100px;
}

div { 
  box-sizing: border-box; 
  max-height: 150px; 
  overflow: auto;
} 

for all 5 challenges should get you through w/o fail. Although it's good practice, you're typing way too much. I tried using "overflow: scroll;" at first too, but since the text is only truncated vertically, "auto" will do the trick and only give you a vertical scroll bar. That question is tricky, but if you read it again, it says "if and where they are needed" in regards to scroll bars.

Cheers!

it's works .main { max-height: 150px; box-sizing: border-box; }

Guil Hernandez
STAFF
Guil Hernandez
Treehouse Teacher

Dan Ridley,

I didn't want to give the full answer here, but I guess that helps too :)

Sorry Guil Hernandez My bad. Helped a little too much there

I was re-watching the video when Dan replied so it dosent matter to much. As i figured it out by watching the video again.

Thank you both Guil Hernandez Dan Ridley for all your help.

Guil Hernandez
STAFF
Guil Hernandez
Treehouse Teacher

No worries - thanks for the help, Dan Ridley. Nice work, guys!

It doesn't work for me :(. Help please. This is what I typed

 a {  
    display:inline-block; width:100px;
 }
.main {
     box-sizing:padding-box;
 }
Guil Hernandez
Guil Hernandez
Treehouse Teacher

Hi Carlos Santiago,

Try the border-box value for box-sizing.

my code isn't working:

div[class='main'] { box-sizing: border-box; -moz-box-sizing: border-box; max-height: 150px; overflow: scroll; }

Or I should say, not passing. It works.

thx:P

This is the correct answer. This one is a pain.

.main {
  box-sizing: border-box; 
}

nav a {
    display: inline-block;
  width: 100px;
}

.main {box-sizing: border-box;}

Correct answer for challenge question:

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.

The solution is here:

'''.main { box-sizing: border-box; }

nav a { display: inline-block; width: 100px; }'''