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
Richard Mockford
3,476 PointsWidth, 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
Carlos Santiago
Courses Plus Student 1,850 PointsYeyy it worked! I was so annoyed! Thanks Guil ^^,
Dan Ridley
Courses Plus Student 14,839 PointsHey 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
Treehouse TeacherHi 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 :)
Michael Tupper
14,633 PointsGuil,
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
Treehouse TeacherExcellent 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!
Andrew Lasick
2,348 PointsI 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!
eric ka
6,929 Pointsit's works .main { max-height: 150px; box-sizing: border-box; }
Guil Hernandez
Treehouse TeacherI didn't want to give the full answer here, but I guess that helps too :)
Dan Ridley
Courses Plus Student 14,839 PointsSorry Guil Hernandez My bad. Helped a little too much there
Richard Mockford
3,476 PointsI 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
Treehouse TeacherNo worries - thanks for the help, Dan Ridley. Nice work, guys!
Carlos Santiago
Courses Plus Student 1,850 PointsIt 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
Treehouse TeacherHi Carlos Santiago,
Try the border-box value for box-sizing.
michaellesniak
10,443 Pointsmy 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.
juravlea nicolae
Courses Plus Student 2,472 Pointsthx:P
John Salzarulo
6,596 PointsThis is the correct answer. This one is a pain.
.main {
box-sizing: border-box;
}
nav a {
display: inline-block;
width: 100px;
}
sergio verdeza
Courses Plus Student 10,765 Points.main {box-sizing: border-box;}
sergio verdeza
Courses Plus Student 10,765 PointsCorrect 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.
Matias Valenzuela
7,554 PointsThe solution is here:
'''.main { box-sizing: border-box; }
nav a { display: inline-block; width: 100px; }'''
Guil Hernandez
Treehouse TeacherGuil Hernandez
Treehouse TeacherNo problem, Carlos. Technically, your answer was correct. Border-box is just more of a commonly used "catch-all" fix for box model issues.