Skip to content

Instantly share code, notes, and snippets.

@ericponto
Last active December 16, 2015 23:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ericponto/5515856 to your computer and use it in GitHub Desktop.
Save ericponto/5515856 to your computer and use it in GitHub Desktop.
Simple responsive grid using LESS generated by looping through the number of columns.
/* VARS */
@grid-columns: 12;
@grid-padding: 1em;
@grid-breakpoint: 45em;
/* MIXINS */
.box-sizing() {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
.clearfix() {
*zoom: 1;
&:before,
&:after {
display: table;
content: "";
line-height: 0;
}
&:after {
clear: both;
}
}
/* Grid container */
.grid {
width: 100%;
.box-sizing();
/* Row */
&-row {
.clearfix();
}
}
/* Mobile first...all columns 100% width */
[class*="grid-col"] {
width: 100%;
padding: @grid-padding;
float: left;
.box-sizing();
}
/* Mixing to calc column width by looping */
.grid-columns ( @number ) when ( @number > 0 ) {
.grid-col-@{number} {
width: percentage(floor(@number * 1000000000 / 12) / 1000000000);
}
.grid-columns(@number - 1);
}
@media (min-width: @grid-breakpoint) {
.grid { padding: 0 5%; }
/* Generate the grid columns */
.grid-columns(@grid-columns);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment