Created
May 17, 2014 17:29
-
-
Save argyleink/6c79c8ace001ecc69751 to your computer and use it in GitHub Desktop.
CSS Flexbox Grid
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// as seen here: https://github.com/zemirco/flexbox-grid/blob/master/flexbox-grid.styl | |
@import 'nib' | |
// variables | |
var-columns = 12 | |
var-gutter-width = 1rem | |
// some styles that apply to all columns - makes final css nicer | |
$common-column-styles | |
box-sizing(border-box) | |
padding-left var-gutter-width | |
padding-right var-gutter-width | |
// wrapper around our rows | |
.container | |
@extend $common-column-styles | |
// the row | |
.row | |
box-sizing(border-box) | |
display flex | |
flex-wrap wrap | |
margin-left - var-gutter-width | |
margin-right - var-gutter-width | |
// generates col-xs-1, col-xs-2, ..., col-xs-12 | |
grid(klass) | |
for num in (1..var-columns) | |
.col-{klass}-{num} | |
@extend $common-column-styles | |
// !important is needed to override .row > div | |
flex-basis (100/var-columns)%*num !important | |
// generates col-xs-offset-1, col-xs-offset-2, ..., col-xs-offset-11 | |
offset(klass) | |
for num in (1..var-columns - 1) | |
.col-{klass}-offset-{num} | |
margin-left (100/var-columns)%*num | |
// use flex for auto width columns | |
.col-auto | |
@extend $common-column-styles | |
// !important is needed to override .row > div | |
flex 1 1 0 !important | |
// set default style to full width | |
// so we don't have to use col-xs-12 every time we want a column to be full width on xs screen | |
.row > div | |
flex-basis 100% | |
// generate default / mobile first xs grid | |
grid('xs') | |
offset('xs') | |
// tablet styles | |
@media (min-width: 768px) | |
grid('sm') | |
offset('sm') | |
// desktop styles | |
@media (min-width: 992px) | |
grid('md') | |
offset('md') | |
// large styles | |
@media (min-width: 1200px) | |
grid('lg') | |
offset('lg') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment