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

General Discussion

lars gutkind
lars gutkind
716 Points

suggestion for:Code Challenge: Creating Flexible Margins

is it really that important to fill in 1.5625% over 1.56% .. feels a litteblit to precise for a quiz , a tip would be to have a solution/hint button to help, so we dont have to guess why the test failed.

is that precision really needed, in web-development ?

2 Answers

James Barnett
James Barnett
39,199 Points

@lars -

The key to understanding this, is that when you are converting pixels to percentages, in most cases the fractions of pixels are dropped, not rounded up.

Let's look at the math ...

  • 0.0156 * 640 = 9.984
  • 0.015625 * 640 = 10.0
  • 0.016 * 640 = 10.24

So if you use 1.56% and drop the fraction, you end up with a 9 instead of 10 pixel margin. However if you use 1.6% you end up with a 10 pixel margin.

This is due to a combination of how the math works, with how sub-pixel rendering works in most browsers.

lars gutkind
lars gutkind
716 Points

aha i see.. thank you so much for the really good explanation, it make sense to me now :D