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 Unused CSS Stages Media Queries Adaptive Layouts with Media Queries

What's the math on the long-decimal percentages for width?

How are you arriving at those percentages?

1 Answer

Laura Cressman
Laura Cressman
12,548 Points

Though I do not remember the specifics, I can imagine they are calculating the percentages as the width of the element they are setting, for example a picture, divided by the width of the container element, like the entire page. For example, if I have a 100px picture that I want to maintain at the same relative size to its 400px parent element, like a div, then I would set the width to 100/400 * 100%, or in this case 25%. That way, when the width of the parent div changes, the picture will scale appropriately. I'm guessing they do the same thing, but sometimes the math doesn't work out as nicely. Does that make sense? Cheers, Laura :)