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

Brenda Krafft
Brenda Krafft
18,036 Points

Long percentages in adaptive Media Queries

OK, I get that you want to be as detailed as possible with this, but how do you come up with these long percentage values? What's the math behind that?

2 Answers

Jacob Miller
Jacob Miller
12,466 Points

Target ÷ Context = Result. So for example, if you wanted to convert a margin of 21px into a percentage. Lets say the margin is on a div inside the body element which has a max-width of 960px. So the math would be: 21 ÷ 960 = 0.021875. Then you convert that into a percentage by moving the decimal point two places to the right. So your percentage would be 2.1875%. Some combinations of target and context will produce those really long decimals that you see in the code challenge.

Brenda Krafft
Brenda Krafft
18,036 Points

Excellent! Thank you; that makes total sense now.