Skip to content

Instantly share code, notes, and snippets.

@harryfk
Created May 29, 2012 07:58
Show Gist options
  • Select an option

  • Save harryfk/2823191 to your computer and use it in GitHub Desktop.

Select an option

Save harryfk/2823191 to your computer and use it in GitHub Desktop.
Sass based, fluid grid
// the basics
*
+box-sizing(border-box)
@mixin width($percent, $alignment: null)
@if $percent == 33
$percent: 33.334
@if $percent == 66
$percent: 66.667
@if $alignment == left
+append(100 - $percent)
@if $alignment == right
+prepend(100 - $percent)
@if $alignment == center
+prepend((100 - $percent) / 2)
+append((100 - $percent) / 2)
width: $percent * 1%
+inline-block
vertical-align: top
@mixin prepend($percent)
@if $percent == 33
$percent: 33.334
@if $percent == 66
$percent: 66.667
margin-left: $percent * 1%
@mixin append($percent)
@if $percent == 33
$percent: 33.334
@if $percent == 66
$percent: 66.667
margin-right: $percent * 1%
// usage:
#page
+width(100)
#main
+width(100)
@media only screen and (min-width: 1024px)
+width(66)
#sidebar
+width(100)
@media only screen and (min-width: 1024px)
+width(33)
#footer
+width(80, center)
#some_box
+prepend(30)
+width(50)
+append(20)
/*
inline-blocks have that nasty 4px margin problem;
work around it by either setting margin-right: -4px on
the width-mixin or by removing all whitespace between
tags (e.g. in Django by using a spaceless block)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment