skip to main content

Responsive Grid System

HTML Example

Youre gonna have to view the source to grab the code here. fa-camera-retro

The Markup

Im only showing sample code for a 3 column layout here, but the Responsive Grid System goes all the way to 12, baby!

The HTML

<div class="section group">
	<div class="col span_1_of_3">
	This is column 1
	</div>
	<div class="col span_1_of_3">
	This is column 2
	</div>
	<div class="col span_1_of_3">
	This is column 3
	</div>
</div>

					

The CSS

/*  SECTIONS  */
.section {
	clear: both;
	padding: 0px;
	margin: 0px;
}

/*  COLUMN SETUP  */
.col {
	display: block;
	float:left;
	margin: 1% 0 1% 1.6%;
}
.col:first-child { margin-left: 0; }


/*  GROUPING  */
.group:before,
.group:after {
	content:"";
	display:table;
}
.group:after {
	clear:both;
}
.group {
    zoom:1; /* For IE 6/7 */
}

/*  GRID OF THREE  */
.span_3_of_3 {
	width: 100%;
}
.span_2_of_3 {
	width: 66.1%;
}
.span_1_of_3 {
	width: 32.2%;
}

/*  GO FULL WIDTH AT LESS THAN 480 PIXELS */

@media only screen and (max-width: 480px) {
	.col { 
		margin: 1% 0 1% 0%;
	}
}

@media only screen and (max-width: 480px) {
	.span_3_of_3 {
		width: 100%; 
	}
	.span_2_of_3 {
		width: 100%; 
	}
	.span_1_of_3 {
		width: 100%;
	}
}


					

How It Works

.section

splits up the page horizontally. Youll need a few of these to break up the content, and you can use them in your main wrapper, or within other divs.

.col

divides the section into columns. Each column has a left margin of 1.6% (around 20 pixels on a normal monitor), except the first one. Using .col:first-child { margin-left: 0; } means you dont need to use class="last" anywhere. It works in all browsers since IE6.

.group

solves floating problems, by forcing the section to self clear its children (aka the clearfix hack). This is good in Firefox 3.5+, Safari 4+, Chrome, Opera 9+ and IE 6+.

.span_1_of_3

specifies the width of the column. Using percentages means its 100% fluid.

@media queries

as soon as the screen size gets less than 480 pixels the columns stack and the margins disappear.


Hey did you notice that this page layout has 4 columns in some places, 3 in others and even 8 a bit further down*? Thats because of the goodness baked right into the Responsive Grid System!

* provided youre looking at it on a screen larger than 768 pixels wide. On smaller screens its, like, responsive.

Two Columns

1 of 2
1 of 2

Three Columns

1 of 3
1 of 3
1 of 3

Four Columns

1 of 4
1 of 4
1 of 4
1 of 4

Five Columns

1 of 5
1 of 5
1 of 5
1 of 5
1 of 5

Six Columns

1 of 6
1 of 6
1 of 6
1 of 6
1 of 6
1 of 6

Seven Columns

1 of 7
1 of 7
1 of 7
1 of 7
1 of 7
1 of 7
1 of 7

Eight Columns

1 of 8
1 of 8
1 of 8
1 of 8
1 of 8
1 of 8
1 of 8
1 of 8

Nine Columns

1 of 9
1 of 9
1 of 9
1 of 9
1 of 9
1 of 9
1 of 9
1 of 9
1 of 9

Ten Columns

1 of 10
1 of 10
1 of 10
1 of 10
1 of 10
1 of 10
1 of 10
1 of 10
1 of 10
1 of 10

Eleven Columns

1 of 11
1 of 11
1 of 11
1 of 11
1 of 11
1 of 11
1 of 11
1 of 11
1 of 11
1 of 11
1 of 11

Twelve Columns

1 of 12
1 of 12
1 of 12
1 of 12
1 of 12
1 of 12
1 of 12
1 of 12
1 of 12
1 of 12
1 of 12
1 of 12