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 Build a Responsive Website Creating a Fluid Foundation Scalable Images

Snow Fall
Snow Fall
1,751 Points

Convert padding of a container with 10px that's inside a container with width: 700px I answer 1.4% but wrong! How?!

I convert the padding based on the parent container's width and the answer is stated as wrong. I don't see how or understand why. Assistance is greatly obliged!

index.html
<!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, .icing, .cake, .filling {
                box-sizing:border-box;
                -moz-box-sizing:border-box; /* Firefox */
                -webkit-box-sizing:border-box; /* Safari */
            }
            .container {
                max-width: 700px;
            }
            .icing {
                background-color: #B4C34F;
                width: 100%; /*700px*/
        padding: 10px;
            }
            .cake {
                background-color: #f8748f;
                width: 85.714285714%; /*600px*/
        margin: 1.428571429%;
        padding: 1.428571;
            }
            .filling {
                background-color: #4FB69F;
                width: 83.33333333%; /*500px*/ 
        margin: 1.6666666666%;
        padding: 10px;
            }

        </style>        
    </head>
    <body>
        <div class="container" id="container">
        <div class="icing">
            <p>Icing</p>
            <div class="cake">
                <p>Cake</p>
                <div class="filling">
                    <p>Filling</p>
                </div>
            </div>
        </div>
        </div>
    </body>
</html>

4 Answers

Hi,

If this is for the cake class it looks to be 600px rather than 700px meaning the value would be 1.6666666666% instead:

.cake {
        background-color: #f8748f;
        width: 85.714285714%; /*600px*/
        margin: 1.428571429%;
        padding: 1.6666666666%;
}

Hope that helps

-Rich

Snow Fall
Snow Fall
1,751 Points

BTW...I did add the "%" on the padding and it's still stated wrong.

Snow Fall
Snow Fall
1,751 Points

OMG!! That worked although I did try 1.6% and it didn't work. At any rate, why did that work? When we convert the margins we use the parent width as the context correct? For example: 10/700 (in the above case).

With that said, we do NOT use the same for padding? Instead we use the current container's width?

Thank you soooo much again. I honestly didn't believe anyone was going to answer, especially not so quickly.

No problem. Happy to help.

The challenge is asking: Convert the padding on .cake from pixels to percentages.

So you would focus on the cake class and don't worry about the rest for now.

It says the width of that particular class is 600px in the comment and the padding is set to 10px so 10/600 and then x100 to get the value :)

Hope that helps clear it up a little.

-Rich

Snow Fall
Snow Fall
1,751 Points

Greatly. Thank you!