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

Design

converting px to % when target and container have an equal value?

hi guys,

i'm doing the responsive design module and there's an exercise where you are asked to convert a 10px margin of an element (target) where its container margin(context) is also 10px.

by my calculations target(10px)/context(10px) = Result(1, which 100%). That answer,100%, returns as incorrect though. what am i missing?

2 Answers

Johan Hernández
Johan Hernández
4,141 Points

Your context margin 10px? The formula is not target (actual margin in px) / into the margin of anything... It should be more like this your current px margin 10px / (lets say 1000px) of your container it would be = 1% I hope it helps.

So lets say, div 1 width = 1000px div 2 margin = 1% so the width would be = 998px

hi Johan,

Thanks for your response. You've solved my problem, i was using margin for context instead of width. i've got the answer correct now.

Thanks again for taking the time to respond.