diff options
| author | Gleb Mazovetskiy <[email protected]> | 2014-12-11 15:16:42 +0000 |
|---|---|---|
| committer | Gleb Mazovetskiy <[email protected]> | 2014-12-11 15:16:42 +0000 |
| commit | 76d6b17f4f7f90fbb185f593c412c6677adb20ef (patch) | |
| tree | 49649745ffaee2bba312ee89a00270579ecbf0fb | |
| parent | 63d4423fc0c7b90bb3faef09991e570886bbc071 (diff) | |
| parent | 5fefe06c3d9d3e568d030be2612e709119c6739e (diff) | |
| download | bootstrap-76d6b17f4f7f90fbb185f593c412c6677adb20ef.tar.xz bootstrap-76d6b17f4f7f90fbb185f593c412c6677adb20ef.zip | |
Merge pull request #6 from twbs/grid-framework-refactor
Refactor grid_framework
| -rw-r--r-- | scss/_variables.scss | 2 | ||||
| -rw-r--r-- | scss/mixins/_grid-framework.scss | 104 |
2 files changed, 48 insertions, 58 deletions
diff --git a/scss/_variables.scss b/scss/_variables.scss index 5f41979f0..8f9e26d68 100644 --- a/scss/_variables.scss +++ b/scss/_variables.scss @@ -294,7 +294,7 @@ $screen-xs-max: ($screen-sm-min - .1); //== Grid system // //## Define your custom responsive grid. - +$grid-breakpoints: (xs sm md lg xl); //** Number of columns in the grid. $grid-columns: 12; //** Padding between columns. Gets divided in half for the left and right. diff --git a/scss/mixins/_grid-framework.scss b/scss/mixins/_grid-framework.scss index b75517d29..3eecbae8b 100644 --- a/scss/mixins/_grid-framework.scss +++ b/scss/mixins/_grid-framework.scss @@ -3,79 +3,69 @@ // Used only by Bootstrap to generate the correct number of grid classes given // any value of `$grid-columns`. -// [converter] This is defined recursively in LESS, but Sass supports real loops -@mixin make-grid-columns($i: 1, $list: ".col-xs-#{$i}, .col-sm-#{$i}, .col-md-#{$i}, .col-lg-#{$i}, .col-xl-#{$i}") { - @for $i from (1 + 1) through $grid-columns { - $list: "#{$list}, .col-xs-#{$i}, .col-sm-#{$i}, .col-md-#{$i}, .col-lg-#{$i}, .col-xl-#{$i}"; - } - #{$list} { +// Common properties for all breakpoints +@mixin make-grid-columns($columns: $grid-columns, $breakpoints: $grid-breakpoints) { + %grid-column { position: relative; // Prevent columns from collapsing when empty min-height: 1px; // Inner gutter via padding - padding-left: ($grid-gutter-width / 2); + padding-left: ($grid-gutter-width / 2); padding-right: ($grid-gutter-width / 2); } -} - - -// [converter] This is defined recursively in LESS, but Sass supports real loops -@mixin float-grid-columns($class, $i: 1, $list: ".col-#{$class}-#{$i}") { - @for $i from (1 + 1) through $grid-columns { - $list: "#{$list}, .col-#{$class}-#{$i}"; - } - #{$list} { - float: left; + @for $i from 1 through $columns { + @each $breakpoint in $breakpoints { + .col-#{$breakpoint}-#{$i} { + @extend %grid-column; + } + } } } - -@mixin calc-grid-column($index, $class, $type) { - @if ($type == width) and ($index > 0) { - .col-#{$class}-#{$index} { - width: percentage(($index / $grid-columns)); - } - } - @if ($type == push) and ($index > 0) { - .col-#{$class}-push-#{$index} { - left: percentage(($index / $grid-columns)); - } - } - @if ($type == push) and ($index == 0) { - .col-#{$class}-push-0 { - left: auto; - } - } - @if ($type == pull) and ($index > 0) { - .col-#{$class}-pull-#{$index} { - right: percentage(($index / $grid-columns)); - } +// Breakpoint-specific properties +@mixin make-grid($breakpoint, $columns: $grid-columns) { + // Work around cross-media @extend (https://github.com/sass/sass/issues/1050) + %grid-column-float-#{$breakpoint} { + float: left; } - @if ($type == pull) and ($index == 0) { - .col-#{$class}-pull-0 { - right: auto; + @for $i from 1 through $columns { + .col-#{$breakpoint}-#{$i} { + @extend %grid-column-float-#{$breakpoint}; + @include grid-column-width($i, $columns); } } - @if ($type == offset) { - .col-#{$class}-offset-#{$index} { - margin-left: percentage(($index / $grid-columns)); + @each $modifier in (pull, push, offset) { + @for $i from 0 through $columns { + .col-#{$breakpoint}-#{$modifier}-#{$i} { + @include grid-column-modifier($modifier, $i, $columns) + } } } } -// [converter] This is defined recursively in LESS, but Sass supports real loops -@mixin loop-grid-columns($columns, $class, $type) { - @for $i from 0 through $columns { - @include calc-grid-column($i, $class, $type); - } +@mixin grid-column-width($index, $columns) { + width: percentage($index / $columns); +} + +@mixin grid-column-push($index, $columns) { + left: if($index > 0, percentage($index / $columns), auto); +} + +@mixin grid-column-pull($index, $columns) { + right: if($index > 0, percentage($index / $columns), auto); } +@mixin grid-column-offset($index, $columns) { + margin-left: percentage($index / $columns); +} -// Create grid for specific class -@mixin make-grid($class) { - @include float-grid-columns($class); - @include loop-grid-columns($grid-columns, $class, width); - @include loop-grid-columns($grid-columns, $class, pull); - @include loop-grid-columns($grid-columns, $class, push); - @include loop-grid-columns($grid-columns, $class, offset); -}
\ No newline at end of file +// Work around the lack of dynamic mixin @include support (https://github.com/sass/sass/issues/626) +@mixin grid-column-modifier($type, $index, $columns) { + @if $type == push { + @include grid-column-push($index, $columns); + } @else if $type == pull { + @include grid-column-pull($index, $columns); + } @else if $type == offset { + @include grid-column-offset($index, $columns); + } +} |
