Skip to content

Instantly share code, notes, and snippets.

@markdurrant
Created August 13, 2012 16:10
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save markdurrant/3342233 to your computer and use it in GitHub Desktop.
Save markdurrant/3342233 to your computer and use it in GitHub Desktop.
Sass fluid grid generator mixin based on Twitter Bootstrap fluid grid.
// =======================================================================
// Fluid Grid Generator Mixin
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//
// Based on fluid grid from http://twitter.github.com/bootstrap/
// =======================================================================
//
//
// Parameters
// =======================================================================
// $number-of-columns - Number of columns for generated grid.
// $gutter-width - Width of gutter for generated grid. (must be percentage value.)
// $row-class-name - Class name for rows in generated grid.
// $column-class-name - Class name for columns in generated grid.
//
// Example @include.
// =======================================================================
// @include fluid-grid-generator (12, 2.5%, row, columns);
@mixin fluid-grid-generator ($number-of-columns, $gutter-width, $row-class-name, $column-class-name) {
// Row styles.
// =====================================================================
.#{$row-class-name} {
width: 100%;
*zoom: 1;
&:before,
&:after {
display: table ;
content: "";
}
&:after {
clear: both;
}
// Column styles. (any direct children of a row)
// =====================================================================
& > *{
display: block;
float: left;
margin-left: $gutter-width;
&:first-child {
margin-left: 0;
}
}
} // End of row styles.
// Individual column widths generator.
// =====================================================================
// Set width of each column.
$column-width: (100% - $gutter-width * ($number-of-columns - 1)) / $number-of-columns;
// Set counter to equal number of columns.
$i: $number-of-columns;
// For each column calculate width.
@while $i > 0 {
%#{$column-class-name}#{$i} {
width: ($column-width * $i) + ($gutter-width * ($i - 1));
}
$i: $i - 1;
} // End of individual column widths generator.
} // End of Fluid Grid Generator Mixin.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment