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 the Grid Container

not floating

Hello If you run this code below you will see that the 2 paragraphs, that are supposed to be columns, are not floating to the left. Do you unserstand why they are not floating to the left?

thanks

<!DOCTYPE html>
<html>
<head>
    <title>Layout</title>
    <meta name="viewport" content="width=device-width">
    <link rel="stylesheet" href="css/normalize.css">
    <style>
    .grid-container{
    padding:0 20px;
    margin:0 auto;
    box-sizing:border-box;

    }

    img{
    width:100%;
    }
    @media (min-width:768px){
      .grid-container > [class=^"grid-"]{
       float:left;
       padding:0 10px;
       min-height:1px;
       margin-left:2px;



   }
   .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%;
    }




    }
    </style>
    <style>
    body{
    font: normal 1.1em/1.5 sans-serif;
    color: #222;
    background:  #edeff0;
    }
    img{
    border:1px solid;
    padding:5px;

    }

    .main-header{
    padding:10px;
    background-color: #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-decoration:none;
    text-align:center;
    border-radius:5px;

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

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

    }
    @media(min-width:768px){
    .grid-container > [class=^"grid"]{

    box-sizing:border-box;
    }

    .main-header{
    position:fixed;
    top:0;
    width:100%;

    }
    .main-nav li{
    display:inline-block;
    margin-top:6px;
    margin-left:10px;

    }
    .main-banner {
        background: #dfe2e4;
        text-align: center;
        padding: 50px 15px;
        margin-bottom: 20px;
    }
    .feat-img{
    width:30%;
    margin-right:10px;
    float:left;

    }
    .group:after,
    .grid-container:after{
     content:" ";
     display:table;
     clear:both;

    }

    }
    @media(min-width:1px) and (max-width:767px){

    .main-nav li{
    margin-top:12px;

    }

    }
    </style>


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

        <div class="main-banner">
            <h1>This is the Main Banner Heading</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>

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

</body>
</html>

1 Answer

I made a few adjustments not sure if you wanted this to happen.

I made changes to the code under the mark up section like this.

<div class="grid-10">
                <h2>Primary Content</h2>
                <img class="feat-img" src="http://lorempixel.com/400/300" />
                <p class="classIadded">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 class="classIadded">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>

I also added a some code to the CSS part to get it to show columns side by side.

  .classIadded{
    width:30%;
    margin-right:10px;
        margin-left:20px;
    float:left;
        display:block;

I know it may not be the best way to code it, but maybe it will give you ideas on what needs to be done to get the results you want.

<!DOCTYPE html>
<html>
<head>
    <title>Layout</title>
    <meta name="viewport" content="width=device-width">
    <link rel="stylesheet" href="css/normalize.css">
    <style>

    .grid-container{
    padding:0 20px;
    margin:0 auto;
    box-sizing:border-box;
    display:inline;     
    }

    img{
    width:100%;
    }
    @media (min-width:768px){
      .grid-container > [class=^"grid-"]{
       float:left;
       padding:0 10px;
       min-height:1px;
       margin-left:2px;



   }
   .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%;
    }




    }
    </style>
    <style>
    body{
    font: normal 1.1em/1.5 sans-serif;
    color: #222;
    background:  #edeff0;
    }
    img{
    border:1px solid;
    padding:5px;

    }

    .main-header{
    padding:10px;
    background-color: #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-decoration:none;
    text-align:center;
    border-radius:5px;

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

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

    }
    @media(min-width:768px){
    .grid-container > [class=^"grid"]{

    box-sizing:border-box;
    }

    .main-header{
    position:fixed;
    top:0;
    width:100%;

    }
    .main-nav li{
    display:inline-block;
    margin-top:6px;
    margin-left:10px;

    }
    .main-banner {
        background: #dfe2e4;
        text-align: center;
        padding: 50px 15px;
        margin-bottom: 20px;
    }
    .feat-img{
    width:30%;
    margin-right:30px;
    float:left;

    }
       .classIadded{
    width:30%;
    margin-right:10px;
        margin-left:20px;
    float:left;
        display:block;

    }
    .group:after,
    .grid-container:after{
     content:" ";
     display:table;
     clear:both;

    }

    }
    @media(min-width:1px) and (max-width:767px){

    .main-nav li{
    margin-top:12px;


    }

      classIadded{

    float:left;
        display:block;

    }

    }
    </style>


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

        <div class="main-banner">
            <h1>This is the Main Banner Heading</h1>
            <p>Andouille pork chop pancetta drumstick ground round beef ribs swine brisket ham.</p>
        </div>
        <div class="grid-container group">

            <div class="grid-10">
                <h2>Primary Content</h2>
                <img class="feat-img" src="http://lorempixel.com/400/300" />
                <p class="classIadded">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 class="classIadded">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>

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





</body>
</html>