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

CSS CSS Layout Techniques Grid Layout Creating Fluid Grid Columns

trouble with grid

Hello!

1) Could you please tell me the reason why the .grid-container and grid-... in the body of this page is not working. I have defined a float in .grid-container > [class^=] and I have giving it a clear fix, but the second column with a class of grid-4 is not floating nicely next to the first column with a class of grid-8. If you solve this problem, please explain briefly in easy to understand words why your solution works.

2) I gave the .main-logo a font-size of 1.5em and in the web console it appears as 24px. But the body has 1.1/1.5em sans-serif; Shouldnt the .main-logo be computed from (1.1 x 16 = 17.6px; 17.6px X 1.5 = 26.4px). Why is the .main-logo's font-size multiplied by 16px instead of 17.6px? what is the general rule for a situation like this.

Cheers!

<!DOCTYPE html>
<html>
<head>
    <title>Grid Layout</title>
    <meta name="viewport" content="width=device-width">
    <link rel="stylesheet" href="css/normalize.css">
    <style>
        .feat-img{
        width:100%;

        }
        .grid-container{
        padding-left:10px;
        padding-right:10px;
        margin-left:auto;
        margin-right:auto;



        }

        /*styling the grid*/

        @media(min-width:768px)
        {

            .grid-container > [class="grid-"]
            {
                padding-left:10px;
                padding-right:10px;
                min-height:1px;
                float:left;
                margin-left:2%;

            }
            .grid-container > [class^="grid-"]:first-child{
            margin-left:0;



            }
            .grid-container > [class^="grid-"]:last-child{
            float:right;
            }

            .grid-1{
            width:6.5%;

            }
            .grid-2{
            width:15%;

            }
            .grid-3{
            width:23.5%;

            }
            .grid-4 {
            width: 32%;
            }
            .grid-5 {
                width: 40.5%;
            }
            .grid-6 {
                width: 49%;
            }
            .grid-7 {
                width: 57.5%;
            }
            .grid-8 {
                width: 66%;
            }
            .grid-9 {
                width: 74.5%;
            }
            .grid-10 {
                width: 83%;
            }
            .grid-11 {
                width: 91.5%;
            }
            .grid-12 {
                width: 100%;
            }

            .group::after{
            content:" ";
            display:table;
            clear:both;


            }





        }


    </style>
    <style>
    /*general style*/

    *{
    box-sizing:border-box;

    }
    body{
    font:1.1/1.5em sans-serif;
    color:#222;
    background:#edeff0;

    }
    img{
    border:1px solid;
    padding:5px;
    }

    /*styling the header*/

    .main-header{
    padding-top:10px;
    padding-bottom:10px;
    background:#384047; 

    }
    .main-logo{
    margin-top:0;
    margin-bottom:0;
    font-size:1.5em;

    }
    .main-logo a, 
    .main-nav a{
    display:block;
    padding:10px 20px;
    text-align:center;
    border-radius:5px;
    color:white;
    text-decoration:none;


    }
    .main-logo a{
    background:#5fcf80; 

    }
    .main-nav a{

    background:#3f8abf;
    }
    .main-footer{
    text-align:center;
    margin-top:30px;
    padding:10px;
    background:#3f8abf;

    }

    /*media query */

    @media(min-width:768px)
    {
     .main-nav li{
     margin-top:6px;
     margin-left:8px;
     display:inline-block;


     }
     .main-banner{
     background:#dfe2e4;
     text-align:center;
     padding:50px 15px;
     margin-bottom:20px;

     }
     .feat-img{
     width:45%;
     float:left;
     margin:5px 20px 10px 0;

     }


    }
    @media (min-width:1px) and (max-width:767px)
    {
        .main-nav li{

        margin-top:12px;
        }


    }

    </style>
    <!--
    1) I gave the .main-logo a font-size of 1.5em
    so in  the web console it appears as 24px. But the body
    has 1.1/1.5em sans-serif; Shouldnt the .main-logo be computed from
    (1.1 x 16 = 17.6px; 17.6px X 1.5 = 26.4px). Why is the 
    .main-logo's font-size multiplied by 16px instead of 17.6px? what 
    is the general rule?
    -->
</head>

<body>
    <header class="main-header group">
    <div class="grid-container">
        <h1 class="grid-2 main-logo"><a>Logo</a></h1>
        <ul class="grid-8 main-nav">
            <li><a>Link 1</a></li>
            <li><a>Link 2</a></li>
            <li><a>Link 3</a></li>
            <li><a>Link 4</a></li>


        </ul>
    </div>
    </header>
    <div class="main-banner">
        <h1>This is the main banner</h1>
        <p>Andouille pork chop pancetta drumstick ground round beef ribs swine brisket ham.</p>

    </div>
    <div class="grid-container group">
        <div class="grid-8">
            <h2>Primary Content</h2>
            <img class="feat-img" src="http://lorempixel.com/400/300" />
            <p>Bacon ipsum dolor sit amet chicken pork ground round brisket corned beef ball tip shank tail salami filet mignon ham hock pork belly venison shankle. Pig kielbasa drumstick sausage pork chop boudin. Chicken t-bone salami pork chop, beef ribs kevin ham tri-tip beef venison biltong brisket.</p>
            <p>Venison strip steak meatball chicken, brisket prosciutto sirloin. Capicola drumstick brisket tri-tip salami. Chicken beef jerky, tail turkey prosciutto cow ham sirloin boudin tenderloin.</p>

        </div>
        <div class="grid-4">
            <h3>Secondary Content</h3>
            <p>Strip steak tenderloin kevin swine meatloaf capicola, doner beef turducken pancetta corned beef pork loin shoulder.</p>
            <hr>
            <p>Pork filet mignon leberkas, tail swine venison pancetta turkey shoulder brisket chalkers likes hamburgers.</p>
            <hr>
            <p>Meatball pastrami shoulder, brisket ribeye spare ribs turkey tongue strip steak t-bone.</p>



        </div>

    </div>
    <div class="main-footer">
        <p>&copy;2014 Example Layout</p>

    </div>
</body>

</html>

2 Answers

Hello Cody,

I have just found out the reason my column is not floating left is because I need to give the first-child a float:left too, something like this:

.grid-container > [class="grid-"]
            {
                padding-left:10px;
                padding-right:10px;
                min-height:1px;
                float:left;
                margin-left:2%;

            }
            .grid-container > [class^="grid-"]:first-child{
            margin-left:0;
            float:left;



            }
            .grid-container > [class^="grid-"]:last-child{
            float:right;
            }

1.) .grid-container > [class="grid-"] will only select children of .grid-container whose class is .grid-. To select an element whose class starts with 'grid-' and can have anything after use the * selector. [class="grid-*"]. The reason it doesn't fit snuggly is because this style block never gets applied and your elements are not floating left. Opening up web inspector, applying float: left; to the div, lead me to this conclusion. After that I just needed to figure out why float wasn't being applied.

2.) I can't get your exact numbers to replicate; but it seems that your <h1 class"main-logo">gets the font size of 1.5 but your text is actually inside the<a> which does not get a font-size set in the styling. <a> usually don't inherit; you either need to a{font-size: inherit;} or a{font-size: 1.5em}