Today, I’ve been playing around with SASS and absolutely loving it! The amount of things that’s possible with it is incredible and a total time saver, anyhow, I decided to build CSS Wizardry’s fluid grids in SASS for use on a few projects, why? Well, Fluid Grids are awesome, secondly it’s a lot more semantic thana having grid-3 etc in your markup, as you might have seen with semantic.gs.
I thought a few others might benefit from it so here it is on Github along with a little wordpress template, that’s roughly based on the template that I use for my projects.
Please note, this was thrown together very quickly! So I’ve probably done something really stupid, I should manage to get another look at it later this week, but until then here’s how it basically works.
The code behind it is:
$total-columns:12;
$grid-width:60;
$gutter-width:20;
@mixin wrapper ($total-columns, $grid-width, $gutter-width) {
margin:0 auto;
$padding: $gutter-width / 2;
$max-width:(($total-columns*$grid-width)+($total-columns*$gutter-width))-($padding*2)+px;
padding: $padding+px;
max-width: $max-width;
}
@mixin grids ($total-columns, $grid-width, $gutter-width) {
$total: $total-columns * ($grid-width + $gutter-width);
max-width: $total+px;
width:auto;
clear:both;
margin-top:0px;
margin-left:0px;
margin-bottom:0px;
margin-right:-(($gutter-width / $total) * 100%);
list-style:none;
overflow:hidden;
}
@mixin column ($total-columns, $grid-width, $gutter-width, $grid) {
$total: $total-columns * ($grid-width + $gutter-width);
$gutter: (($gutter-width / $total) * 100)*($grid - 1);
width: (((($grid-width / $total)*$grid) * 100%)+$gutter);
float:left;
margin:0 (($gutter-width / $total) * 100%) 0 0;
}
And to use a grid you simply:
#example{
@include column($grid:5);
}
You state that you’d like to use the Column mixin and pass the column number to the grid variable and that’s it. There’s more on the readme on Github.
Note: yes I do know that things like is are probably around, however I’ve used fluid grids from Harry for a while now and think they’re the dogs bollocks and creating a SASS version for myself was logical, if you have any questions then tweet me!