Skip to content

Instantly share code, notes, and snippets.

@JonCatmull
Created January 19, 2015 11:12
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 JonCatmull/3d0e1b2c6210d75af4a3 to your computer and use it in GitHub Desktop.
Save JonCatmull/3d0e1b2c6210d75af4a3 to your computer and use it in GitHub Desktop.
Special column mixins and functions allowing easy generation of column layouts
@function col($col-width-px, $container-width: $content-width-max) {
@return percentage(strip-unit($col-width-px) / strip-unit($container-width));
}
@mixin col($col-width-px, $container-width: $content-width-max, $gutter-px: none, $float: left) {
float: $float;
display: block;
width: col($col-width-px, $container-width);
@if ($gutter-px != 'none') {
margin-#{if($float == 'left','right','left')}: col($gutter-px,$container-width);
}
}
@mixin cols($col-width-px, $container-width: $content-width-max, $float: left) {
$cols: strip-unit(floor($container-width/$col-width-px));
$gutter-px: ($container-width % $col-width-px) / ($cols - 1);
float: $float;
display: block;
width: col($col-width-px, $container-width);
margin-right: col($gutter-px,$container-width);
&:nth-child(#{$cols}n#{if($float == 'left','','+1')}) {
margin-right: 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment