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

CSS Grids - Issue getting grid to work on a practice page

For some reason, I cannot get my grid to work using CSS. It will not align the <div> in a row or even add a border to each <div>. Can anyone see what I'm doing wrong?

This is what I have. The HTML:

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Gridding Test Field</title>
<link rel="stylesheet" type="text/css" href="css/normalize.css" media="screen">
<link rel="stylesheet" type="text/css" href="css/grid.css" media="screen">
<link rel='stylesheet' type='text/css' href='http://fonts.googleapis.com/css?family=Nunito'>
</head>

<body>
<div class="container clearfix back">
    <div class="grid_8 omega"><p>8</p></div>

    <div class="grid_2 alpha"><p>2</p></div>
    <div class="grid_2"><p>2</p></div>

</div>
</body>
</html>

This is the CSS:

  /*
 Width: 1000px
# Columns : 8
Column width: 104px
Gutter : 24px 

*/

body {
background-color: #222;
}

.grid_1 { width: 104px; }    /* 104px */
.grid_2 { width: 232px; }    /* 232px */
.grid_3 { width: 360px; }    /* 360px */
.grid_4 { width: 488px; }    /* 488px */
.grid_5 { width: 616px; }    /* 616px */
.grid_6 { width: 744px; }    /* 744px */
.grid_7 { width: 872px; }    /* 872px */
.grid_8 { width: 1000px;  }    /* 1000px */


.grid_1,
.grid_2,
.grid_3,
.grid_4,
.grid_5,
.grid_6,
.grid_7,
.grid_8, {
margin: 0 20px 10px 0;
border: 5px dotted #555;
float: left;
display: block;
}

p {
background-color: rgba(25, 255, 58, 0.4);
padding: 5px;
}

.alpha{margin-left:0px;}
.omega{margin-right:0px;}

.container{
max-width: 1000px;
background-color: rgba(25, 180, 238, 0.4);
margin: auto;
}

.clear{
clear: both;
display:block;
overflow:hidden;
visibility:hidden;
width:0;
height:0
}

.clearfix:after{clear:both;
content:' ';
display:block;
font-size:0;
line-height:0;
visibility:hidden;
width:0;
height:0
}

* html .clearfix,*:first-child+html .clearfix{zoom:1}

4 Answers

Hey Scott,

I'm new to grids so I'm still learning about how they work. Forgive me if I'm wrong, but my limited understanding of them is that all grids in a section should add up to the total number of columns defined in the grid.

If this understanding is correct that your final grid div should be grid_6 rather than grid_2. Either that, or you have to define a grid_4 div to close off the section.

Again, I'm only guessing, and there's a 99.9% chance I may be wrong, but I hope I've helped :).

Cheers,

Steve

Hi Scott,

Below CSS line is wrong in your css -

.grid_1,
.grid_2,
.grid_3,
.grid_4,
.grid_5,
.grid_6,
.grid_7,
.grid_8, {
margin: 0 20px 10px 0;
border: 5px dotted #555;
float: left;
display: block;
}

In above css at the end there is no need of comma, below is correct css -

.grid_1,
.grid_2,
.grid_3,
.grid_4,
.grid_5,
.grid_6,
.grid_7,
.grid_8 {
margin: 0 20px 10px 0;
border: 5px dotted #555;
float: left;
display: block;
} 

Wow, that totally just solved a problem that was driving me beyond crazy. I guess that is the problem with copy/paste from the Codepen...too much for newbies to not know.

Oh well, the last hour was not a total loss I guess.

Thanks to both of you for the assistance, I really appreciate it.

My issue was the comma after the .grid_8 class/selector... it's amazing how difficult it can be to spot such simple mistakes!

Hey Team!

One thing that has always helped me is using the markup and style validation tools as suggested by the W3C !

http://www.w3.org/QA/Tools/

But nothing beats taking a mental break from the computer screen, that's for sure, or asking your fellow designer for help :)