Last active
December 10, 2015 13:48
-
-
Save matthewcopeland/4443837 to your computer and use it in GitHub Desktop.
Created a single control point for adding column-classes to the sassygrid by adding sass-loops and an array of column-classes. Related to spree PR https://github.com/spree/spree/pull/2221
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
//--------------------------------------------------------------------------------------------------- | |
// a sassier grid for spree | |
// fixed-width - html whitespace not removed. | |
// intended to be used as magic-classes, coupling markup&style. | |
// based on skeleton v1.1 by dave gamache - thanks dude | |
// | |
//--------------------------------------------------------------------------------------------------- | |
//- Contents | |
//--- Grid classes | |
//--- Grid Variables | |
//--- Grid Mixin | |
//--- Desktop | |
//--- Tablet | |
//--- Mobile | |
//------------------------------------------------------------------------------------------------------- | |
// grid classes | |
// to add another column, add a class this list here. | |
// ONLY here. | |
$column-classes: ( | |
one, | |
two, | |
three, | |
four, | |
five, | |
six, | |
seven, | |
eight, | |
nine, | |
ten, | |
eleven, | |
twelve, | |
thirteen, | |
fourteen, | |
fifteen, | |
sixteen | |
); | |
//------------------------------------------------------------------------------------------------------- | |
// grid variables | |
// get the count of the column classes. | |
$column-count: length($column-classes); | |
$gutter: 20px; | |
$desktop-container-width: 960px; | |
$tablet-container-width: 768px; | |
$mobile-container-width: 90%; | |
$mobile-column-width: 100%; | |
//-------------------------------------------------------------------------------------------------------- | |
// grid mixin | |
@mixin sassy-grid($grid-container-width, $grid-column-count:$column-count, $grid-gutter:$gutter) { | |
$grid-column-width: $grid-container-width/$grid-column-count; | |
.container { | |
width: $grid-container-width; | |
.columns, .column { | |
@for $i from 1 through $column-count { | |
$current-column-class: nth($column-classes, $i); | |
&.#{$current-column-class} { width: #{$i*$grid-column-width - $grid-gutter}; } | |
}//@for | |
&.one-third { width: ($grid-container-width/3) - $grid-gutter; } | |
&.two-thirds { width: (($grid-container-width/3)*2) - $grid-gutter; } | |
}//.columns | |
// offsets | |
@for $i from 1 through $column-count { | |
$current-column-class: nth($column-classes, $i); | |
&.offset-by-#{$current-column-class} { padding-left: #{$i*$grid-column-width}; } | |
}//@for | |
}//.container | |
}//@mixin | |
//--------------------------------------------------------------------------------- | |
// desktop | |
.container { | |
position: relative; | |
margin: 0 auto; | |
padding: 0; | |
}//.container | |
.column, .columns { | |
float: left; | |
display: inline; | |
margin-left: $gutter/2; | |
margin-right: $gutter/2; | |
&.alpha { margin-left: 0; } | |
&.omega { margin-right: 0; } | |
}//.column,.columns | |
.row { margin-bottom: $gutter; } | |
@include sassy-grid($desktop-container-width, $column-count, $gutter); | |
//----------------------------------------------------------------------- | |
// #Tablet | |
@media only screen and (max-width: 959px) { | |
@include sassy-grid($tablet-container-width, $column-count, $gutter); | |
.container { width: $tablet-container-width; } | |
.column, .columns { | |
&.alpha { margin-right: 10px; } | |
&.omega { margin-left: 10px; } }//.column,.columns | |
.alpha.omega { | |
margin-right: 0; | |
margin-left: 0; }//.alpha.omega | |
}//@media | |
//-------------------------------------------------------------------- | |
// #Mobile | |
@media only screen and (max-width: 767px) { | |
.container { | |
width: $mobile-container-width; | |
.column, .columns { | |
margin: 0; | |
@for $i from 1 through $column-count { | |
$current-column-class: nth($column-classes, $i); | |
&.#{$current-column-class} { width: $mobile-column-width; } | |
}//@for | |
}//.column,.columns | |
// offsets | |
// offsets | |
@for $i from 1 through $column-count { | |
$current-column-class: nth($column-classes, $i); | |
&.offset-by-#{$current-column-class} { padding-left: 0; } | |
}//@for | |
}//.container | |
}//@media | |
//------------------------------------------------------------ | |
// Use clearfix class on parent to clear nested columns, | |
// or wrap each row of columns in a <div class="row"> | |
// You can also use a <br class="clear" /> to clear columns | |
@mixin clearfix { | |
clear: both; | |
display: block; | |
overflow: hidden; | |
visibility: hidden; | |
width: 0; | |
height: 0; | |
}//@mixin | |
.clear { @include clearfix; } | |
.clearfix, .row, .container { | |
&:before, &:after { content: ' '; @include clearfix; } | |
}//.clearfix, .row | |
// Note that the clearfix could be better placed in a utilities file. | |
// However the context of grid layout does give some justification for the coupling. | |
//--------------------------------------------------------------------------------------------------- |
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
/* PS: thanks to http://cssconvert.mgwebsolutions.net/ for the quick converter */ | |
.container { | |
position: relative; | |
margin: 0 auto; | |
padding: 0; } | |
.column, .columns { | |
float: left; | |
display: inline; | |
margin-left: 10px; | |
margin-right: 10px; } | |
.column.alpha, .columns.alpha { | |
margin-left: 0; } | |
.column.omega, .columns.omega { | |
margin-right: 0; } | |
.row { | |
margin-bottom: 20px; } | |
.container { | |
width: 960px; } | |
.container .columns.one, .container .column.one { | |
width: 40px; } | |
.container .columns.two, .container .column.two { | |
width: 100px; } | |
.container .columns.three, .container .column.three { | |
width: 160px; } | |
.container .columns.four, .container .column.four { | |
width: 220px; } | |
.container .columns.five, .container .column.five { | |
width: 280px; } | |
.container .columns.six, .container .column.six { | |
width: 340px; } | |
.container .columns.seven, .container .column.seven { | |
width: 400px; } | |
.container .columns.eight, .container .column.eight { | |
width: 460px; } | |
.container .columns.nine, .container .column.nine { | |
width: 520px; } | |
.container .columns.ten, .container .column.ten { | |
width: 580px; } | |
.container .columns.eleven, .container .column.eleven { | |
width: 640px; } | |
.container .columns.twelve, .container .column.twelve { | |
width: 700px; } | |
.container .columns.thirteen, .container .column.thirteen { | |
width: 760px; } | |
.container .columns.fourteen, .container .column.fourteen { | |
width: 820px; } | |
.container .columns.fifteen, .container .column.fifteen { | |
width: 880px; } | |
.container .columns.sixteen, .container .column.sixteen { | |
width: 940px; } | |
.container .columns.one-third, .container .column.one-third { | |
width: 300px; } | |
.container .columns.two-thirds, .container .column.two-thirds { | |
width: 620px; } | |
.container.offset-by-one { | |
padding-left: 60px; } | |
.container.offset-by-two { | |
padding-left: 120px; } | |
.container.offset-by-three { | |
padding-left: 180px; } | |
.container.offset-by-four { | |
padding-left: 240px; } | |
.container.offset-by-five { | |
padding-left: 300px; } | |
.container.offset-by-six { | |
padding-left: 360px; } | |
.container.offset-by-seven { | |
padding-left: 420px; } | |
.container.offset-by-eight { | |
padding-left: 480px; } | |
.container.offset-by-nine { | |
padding-left: 540px; } | |
.container.offset-by-ten { | |
padding-left: 600px; } | |
.container.offset-by-eleven { | |
padding-left: 660px; } | |
.container.offset-by-twelve { | |
padding-left: 720px; } | |
.container.offset-by-thirteen { | |
padding-left: 780px; } | |
.container.offset-by-fourteen { | |
padding-left: 840px; } | |
.container.offset-by-fifteen { | |
padding-left: 900px; } | |
.container.offset-by-sixteen { | |
padding-left: 960px; } | |
@media only screen and (max-width: 959px) { | |
.container { | |
width: 768px; } | |
.container .columns.one, .container .column.one { | |
width: 28px; } | |
.container .columns.two, .container .column.two { | |
width: 76px; } | |
.container .columns.three, .container .column.three { | |
width: 124px; } | |
.container .columns.four, .container .column.four { | |
width: 172px; } | |
.container .columns.five, .container .column.five { | |
width: 220px; } | |
.container .columns.six, .container .column.six { | |
width: 268px; } | |
.container .columns.seven, .container .column.seven { | |
width: 316px; } | |
.container .columns.eight, .container .column.eight { | |
width: 364px; } | |
.container .columns.nine, .container .column.nine { | |
width: 412px; } | |
.container .columns.ten, .container .column.ten { | |
width: 460px; } | |
.container .columns.eleven, .container .column.eleven { | |
width: 508px; } | |
.container .columns.twelve, .container .column.twelve { | |
width: 556px; } | |
.container .columns.thirteen, .container .column.thirteen { | |
width: 604px; } | |
.container .columns.fourteen, .container .column.fourteen { | |
width: 652px; } | |
.container .columns.fifteen, .container .column.fifteen { | |
width: 700px; } | |
.container .columns.sixteen, .container .column.sixteen { | |
width: 748px; } | |
.container .columns.one-third, .container .column.one-third { | |
width: 236px; } | |
.container .columns.two-thirds, .container .column.two-thirds { | |
width: 492px; } | |
.container.offset-by-one { | |
padding-left: 48px; } | |
.container.offset-by-two { | |
padding-left: 96px; } | |
.container.offset-by-three { | |
padding-left: 144px; } | |
.container.offset-by-four { | |
padding-left: 192px; } | |
.container.offset-by-five { | |
padding-left: 240px; } | |
.container.offset-by-six { | |
padding-left: 288px; } | |
.container.offset-by-seven { | |
padding-left: 336px; } | |
.container.offset-by-eight { | |
padding-left: 384px; } | |
.container.offset-by-nine { | |
padding-left: 432px; } | |
.container.offset-by-ten { | |
padding-left: 480px; } | |
.container.offset-by-eleven { | |
padding-left: 528px; } | |
.container.offset-by-twelve { | |
padding-left: 576px; } | |
.container.offset-by-thirteen { | |
padding-left: 624px; } | |
.container.offset-by-fourteen { | |
padding-left: 672px; } | |
.container.offset-by-fifteen { | |
padding-left: 720px; } | |
.container.offset-by-sixteen { | |
padding-left: 768px; } | |
.container { | |
width: 768px; } | |
.column.alpha, .columns.alpha { | |
margin-right: 10px; } | |
.column.omega, .columns.omega { | |
margin-left: 10px; } | |
.alpha.omega { | |
margin-right: 0; | |
margin-left: 0; } } | |
@media only screen and (max-width: 767px) { | |
.container { | |
width: 90%; } | |
.container .column, .container .columns { | |
margin: 0; } | |
.container .column.one, .container .columns.one { | |
width: 100%; } | |
.container .column.two, .container .columns.two { | |
width: 100%; } | |
.container .column.three, .container .columns.three { | |
width: 100%; } | |
.container .column.four, .container .columns.four { | |
width: 100%; } | |
.container .column.five, .container .columns.five { | |
width: 100%; } | |
.container .column.six, .container .columns.six { | |
width: 100%; } | |
.container .column.seven, .container .columns.seven { | |
width: 100%; } | |
.container .column.eight, .container .columns.eight { | |
width: 100%; } | |
.container .column.nine, .container .columns.nine { | |
width: 100%; } | |
.container .column.ten, .container .columns.ten { | |
width: 100%; } | |
.container .column.eleven, .container .columns.eleven { | |
width: 100%; } | |
.container .column.twelve, .container .columns.twelve { | |
width: 100%; } | |
.container .column.thirteen, .container .columns.thirteen { | |
width: 100%; } | |
.container .column.fourteen, .container .columns.fourteen { | |
width: 100%; } | |
.container .column.fifteen, .container .columns.fifteen { | |
width: 100%; } | |
.container .column.sixteen, .container .columns.sixteen { | |
width: 100%; } | |
.container.offset-by-one { | |
padding-left: 0; } | |
.container.offset-by-two { | |
padding-left: 0; } | |
.container.offset-by-three { | |
padding-left: 0; } | |
.container.offset-by-four { | |
padding-left: 0; } | |
.container.offset-by-five { | |
padding-left: 0; } | |
.container.offset-by-six { | |
padding-left: 0; } | |
.container.offset-by-seven { | |
padding-left: 0; } | |
.container.offset-by-eight { | |
padding-left: 0; } | |
.container.offset-by-nine { | |
padding-left: 0; } | |
.container.offset-by-ten { | |
padding-left: 0; } | |
.container.offset-by-eleven { | |
padding-left: 0; } | |
.container.offset-by-twelve { | |
padding-left: 0; } | |
.container.offset-by-thirteen { | |
padding-left: 0; } | |
.container.offset-by-fourteen { | |
padding-left: 0; } | |
.container.offset-by-fifteen { | |
padding-left: 0; } | |
.container.offset-by-sixteen { | |
padding-left: 0; } } | |
.clear { | |
clear: both; | |
display: block; | |
overflow: hidden; | |
visibility: hidden; | |
width: 0; | |
height: 0; } | |
.clearfix:before, .clearfix:after, .row:before, .row:after, .container:before, .container:after { | |
content: ' '; | |
clear: both; | |
display: block; | |
overflow: hidden; | |
visibility: hidden; | |
width: 0; | |
height: 0; } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment