Skip to content

Instantly share code, notes, and snippets.

@richardsweeney
Created November 10, 2012 11:37
Show Gist options
  • Save richardsweeney/4050845 to your computer and use it in GitHub Desktop.
Save richardsweeney/4050845 to your computer and use it in GitHub Desktop.
A mixin for creating grid columns on the fly (pixel based: non-responsive)
$columns: 16;
$gridWidth: 960px;
@mixin drupalCols($rows: 4, $padding: 0 10px) {
width: ($gridWidth / $columns) * $rows;
float: left;
padding: $padding;
@include box-sizing(border-box);
}
.my-div {
@include drupalCols(8);
}
// This becomes:
/*
.my-div {
width: 480px;
float: left;
padding: 0 10px;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
*/
// You can also add more or less padding like this:
.my-div {
@include drupalCols(4, 10px 20px 30px);
}
/*
.my-div {
width: 240px;
float: left;
padding: 10px 20px 30px;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment