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

HTML Build a Responsive Website Creating a Fluid Foundation Creating Flexible Margins

Formula for converting pixels to percentages

I used the cake container measurement of 640 (context) divided it by 10 for 1.56% but it’s not correct?

Using .cake as your context, convert the margins on .filling from pixels to percentages.

<!DOCTYPE html>
<html>
  <head>
    <style>

      /* When setting flexible margin on an element, your context is the width of the element's container.
      When setting flexible padding on an element, your context is the width of the element itself. */

      p {
        margin: 0;
      }
      body {
        color: #fff;
      }
      .container {
        max-width: 800px;
      }

      .icing {
        background-color: #B4C34F;
        width: 100%; /*800px*/
        padding: 10px;
      }
      .cake {
        background-color: #f8748f;
        width: 80%; /*640px*/
        margin: 1.25%;
        padding: 10px;
      }
      .filling {
        background-color: #4FB69F;
        width: 75%; /*480px*/
        margin: 1.56%;
        padding: 10px;
       }
    </style>
  </head>

3 Answers

Tom Bedford
Tom Bedford
15,645 Points

10/640 = 1.5625%

You may need to be more specific.

Hello Tom, Just tried it but no luck... Thanks.

Hi Paula,

The following code worked for me. Maybe refresh the browser page?

Jeff

.filling {
        background-color: #4FB69F;
        width: 75%; /*480px*/
        margin: 1.5625%;
        padding: 10px;
       }