Skip to content

Instantly share code, notes, and snippets.

@a-axton
Created June 30, 2014 01:51
Show Gist options
  • Select an option

  • Save a-axton/4f15d0490d857fa79ba7 to your computer and use it in GitHub Desktop.

Select an option

Save a-axton/4f15d0490d857fa79ba7 to your computer and use it in GitHub Desktop.
Bootstrap style grid using neat and SASS maps
// replace map keys with whatever you want
// creats classes as .grid-$keyname-$col
$breakpoint-widths: (xs: 480px, sm: 768px, md: 992px, lg: 1200px);
$grid-columns: 12
// media query mixin
@mixin mq($search) {
@media (min-width: map-get($breakpoint-widths, $search)){
@content
}
}
@mixin build-grid(){
@each $name, $width in $breakpoint-widths {
@media (min-width: $width){
@for $i from 1 through $grid-columns {
// span-columns() is a neat.bourbon.io function to generate grid width
.grid-#{$name}-#{$i} { @include span-columns($i); }
}
}
}
}
// build grid classes
@include build-grid();
// create media query from map with breakpoint name
@include mq(lg){
body {
background: purple;
}
}
<div class="grid-xs-12 grid-sm-8 grid-med-6 grid-lg-4">Hello World</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment