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 Padding

How do you arrive at the padding percentage values shown in this video?

I did not understand how you can get the percentage value of the padding? Is there like a formula or something?

4 Answers

Matt Varner
Matt Varner
5,373 Points

Hamad,

There is a little bit of helpful information in this related post, also, I think.

Nathaniel Nasarow
Nathaniel Nasarow
10,291 Points

Simply math. Now, if you're looking for a certain padding amount, that's all relative on how you want to design your site. But let's say you want 100 pixels of padding on one side. Now, let's say that your box's total width is 500 pixels. Just divide 500 pixels from 100 (500/100) to get .2, or 20 percent. You can check this by multiplying 500 by .2, and you'll get 100 pixels.

You can get more in depth with this by checking how much space you have in your browser (I recommend mobile first) and then do further math to get what you want, but quite frankly it's pretty simple (and I suck at math!) It will just take a bit of work and artistry.

Source: me. <--beginner.

There isn't necessarily a formula for the percentages, it's relative to the total width. So lets say you want 5% padding or 15% padding. It's how much of the width of the container would you like to use as padding.

Hope this helps

Jake Ford
Jake Ford
9,230 Points

Kind of like Nathaniel said. You just have to look at the size of your box and figure out how much you think it needs. As long as you keep in mind the total width of your box and page, you should be good.