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

Does "width" overwrite "padding"?

Let's say the width of the containing box is 5cm, padding(all sides) is 2cm.

if I set the width of the content to be 50%. Now the absolute value of the width would be 2.5 cm. But if the padding effect is still there, then the box now would be 2+2.5+2 = 6.5cm. But the content would no longer be 50% of width now(2.5/6.5 != 50%).

I'm kinda confused,any help? Thanks!

1 Answer

The size of the container change it's width if you add padding or borders. For Example: If you have a container with 150 px and you add 1px border and 15px padding the width will be 182 (150+1+1+15+15). If you don't want it to change the size use:

box-sizing: border-box;

Don't forget to use the prefix to support different browsers