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
.sectionsplits 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.
.coldivides 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.
.groupsolves 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_3specifies the width of the column. Using percentages means its 100% fluid.
@media queriesas 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.