Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

CSS CSS Basics (2014) The Box Model Padding

18/24?

When he did percentages for the padding - how did he calculate 100px 120px to 18% 24% percent.

Also why don't the instructors comment.. I see so many varied answers its confusing and not as helpful.

I don't believe there was any calculation done to get 18 and 24 percent. It was just for the purpose of showing the differences between pixels and % and the effect it has on the display.

2 Answers

Matthew Long
Matthew Long
28,383 Points

It seems that this time he didn't calculate anything to get the new 18 and 24 percent values. He simply chose those for design purposes. If I remember correctly I believe in a previous exercises he calculated the value of an em or rem using the base font size, but this is something different.

And I agree sometimes it would be helpful for the instructors to go back and comment on questions asked in the forums. I don't expect them to be the first to answer a question, but it would be nice to see them answer here and there I agree.

To calculate how much a percentage is in pixels you have to think the percentage as a fraction, lets say I want my div to be 25% of the parent element(That's how the percentage works).25% is 25/100. Let's assume that the parent element is 500 pixels. 25/100 of ?/500 is 125px. We have to multiply the denominator 100 with some value that will give us 500. And then we multiply the same value with the numerator.