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 :)