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![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Howard Kirk](https://secure.gravatar.com/avatar/143e5cf05d49c2e1d99c5a13bde698b2?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Howard Kirk
2,657 PointsPixels to Percent
From what I understand, converting a margin from pixels to percents is based on the usual formula, with the context being the width of the container. So the question was using .cake as your context, convert the margin on .filling to percent. The pixels on .cake was 640, the pixels on the margin for .filling was 10px. I divided 10 by 640 and came up with 0.015625 - I shifted the dec and came up with a margin of 1.56% - The tutorial questionnaire is telling me that is not correct. What am I missing?
11 Answers
![James Barnett](https://secure.gravatar.com/avatar/43ea08b4fc547e8a5da87c207bea2123?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
James Barnett
39,199 PointsAt the top of the code challenge it gives you some very important instructions
When setting flexible margin on an element, your context is the width of the element's container.
![Zack Perdue](https://secure.gravatar.com/avatar/5a2375d35c30b9b65ce4a2396fad4c78?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Zack Perdue
1,824 Points10/640*100
![Howard Kirk](https://secure.gravatar.com/avatar/143e5cf05d49c2e1d99c5a13bde698b2?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Howard Kirk
2,657 PointsMy original answer was 1.56% and it was rejected
![Zack Perdue](https://secure.gravatar.com/avatar/5a2375d35c30b9b65ce4a2396fad4c78?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Zack Perdue
1,824 Pointswell you left off some decimal places.
![Howard Kirk](https://secure.gravatar.com/avatar/143e5cf05d49c2e1d99c5a13bde698b2?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Howard Kirk
2,657 Points1.562%? Seriously....
![Jackie Keiser](https://secure.gravatar.com/avatar/086c5ab501a97baa31d91f2d83e3a560?s=60&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Jackie Keiser
9,833 PointsWhen you're converting pixels to percents, you don't have to cut it off at two decimal places. If you want it to be exact, use the full number even if it's kind of ridiculous. We're talking about a computer doing these calculations, not a person. Computers are good at this kind of thing.
![James Barnett](https://secure.gravatar.com/avatar/43ea08b4fc547e8a5da87c207bea2123?s=60&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
James Barnett
39,199 PointsIn terms of typing out the actual numbers, I like to round to 3 decimal places because of how the math works out.
![Ian Watkins](https://secure.gravatar.com/avatar/084c7a2f6046eca37dcf2b530ae6bf0e?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Ian Watkins
1,036 PointsTo go along with this one I am working on the first code challenge in scalable image where you need to convert the padding to a percentage in cake I put 1.428571429% but it says that wrong.
Any one have any ideas?
![Toby Bowley](https://secure.gravatar.com/avatar/bcbbd3a4a52ad9fa5485df4487a2a741?s=60&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Toby Bowley
4,145 PointsDon't forget when dealing with percentages you are dealing with the parent, so try dividing it by the margin in the same div, I think that will help.
![Daniel Phelps](https://secure.gravatar.com/avatar/ced47523ac67d3727d5066bdcc7eb3e1?s=60&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Daniel Phelps
3,285 PointsI was also stuck until I tried putting 1.6666666% as my answer and it let me through. I guess since padding is space inside a .cake element, the padding's context is the cake element? It doesn't make complete sense to me, would anybody mind clarifying why it's my 100*10/600 and not 100*10/700?
![Zack Perdue](https://secure.gravatar.com/avatar/5a2375d35c30b9b65ce4a2396fad4c78?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Zack Perdue
1,824 PointsI guess a better answer would have been along the lines of explaining the reasons WHY we use these large calculations instead of how to get them. As long as we get them and that they are correct is all that matters.
width: result = target รท context * 100
I don't like to round my result because I think IE does better with the entire decimal.
![Kevin Silvestre](https://uploads.teamtreehouse.com/production/profile-photos/126178/micro_580268_559910930719361_1803822797_n.jpg)
Kevin Silvestre
13,561 PointsI had the same problem. I solved it by dividing it by 700 instead of 640.
![Joseph Damiani](https://uploads.teamtreehouse.com/production/profile-photos/310692/micro_me.jpg)
Joseph Damiani
1,066 PointsFor example, if you are using 20px as your font size then the percentage would be 125%. 20 / 16 = 1.25. You would always calculate any pixels size with 16. You would move your decimal point to the right 2 times no matter what to get your answer.
![Zack Perdue](https://secure.gravatar.com/avatar/5a2375d35c30b9b65ce4a2396fad4c78?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Zack Perdue
1,824 PointsHere is an example of what i use when i build websites
.inner-container{ padding: 0 6.140350877193%; width: 87.719298245614%; float: left; }
![Zack Perdue](https://secure.gravatar.com/avatar/5a2375d35c30b9b65ce4a2396fad4c78?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Zack Perdue
1,824 PointsI either use a css pre-processor to calculate my %'s.
It goes one of two ways, I use an expression and have it calculated on the fly.
OR I calculate it myself using this plugin I made that calculates expressions that you highlight within your editor (coda) http://zackperdue.com/plugins/coda-math-plugin-computate
Here is also another resource to learn about fluid grids http://www.alistapart.com/articles/fluidgrids/
![James Barnett](https://secure.gravatar.com/avatar/43ea08b4fc547e8a5da87c207bea2123?s=60&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
James Barnett
39,199 PointsZack Perdue - Like when you learned long division as a kid first you learn to do it by hand and when you did more advanced math you learned to use a calculator to speed up the time it took to do the calculations.
The original poster is currently at the stage of learning how to do these calculations by hand talking about using a CSS pre-processor to speed up muddies the waters a bit.
James Barnett
39,199 PointsJames Barnett
39,199 PointsSince you didn't give us a link, the step you were on or the question text I'm guessing here.
Question: Using .cake as your context, convert the margins on .filling from pixels to percentages.
Link: http://teamtreehouse.com/library/build-a-responsive-website/creating-a-fluid-foundation/creating-flexible-margins