diff options
| author | Gleb Mazovetskiy <[email protected]> | 2014-12-05 10:53:43 +0000 |
|---|---|---|
| committer | Gleb Mazovetskiy <[email protected]> | 2014-12-07 13:44:24 +0000 |
| commit | 795a5845619843040b5ab63ff7639fdf9ae86753 (patch) | |
| tree | 7e6fcf2fd587b3f98d5bf5bbaa0661e27b242035 | |
| parent | 57071cc68a8b636d2524663cb6fd95ede8e93aeb (diff) | |
| download | bootstrap-795a5845619843040b5ab63ff7639fdf9ae86753.tar.xz bootstrap-795a5845619843040b5ab63ff7639fdf9ae86753.zip | |
Refactor grid_framework
A more idiomatic refactoring of the grid framework
* Use %-placeholder instead of generating a class name list
* Use if expression
* Remove loop-grid-columns
| -rw-r--r-- | scss/mixins/_grid-framework.scss | 88 |
1 files changed, 37 insertions, 51 deletions
diff --git a/scss/mixins/_grid-framework.scss b/scss/mixins/_grid-framework.scss index b75517d29..5ac62751f 100644 --- a/scss/mixins/_grid-framework.scss +++ b/scss/mixins/_grid-framework.scss @@ -3,79 +3,65 @@ // 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} { - position: relative; - // Prevent columns from collapsing when empty - min-height: 1px; - // Inner gutter via padding - padding-left: ($grid-gutter-width / 2); - padding-right: ($grid-gutter-width / 2); - } +%twbs-grid-column { + position: relative; + // Prevent columns from collapsing when empty + min-height: 1px; + // Inner gutter via padding + padding-left: ($grid-gutter-width / 2); + padding-right: ($grid-gutter-width / 2); } +%twbs-grid-column-float { + float: left +} -// [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; +@mixin make-grid-columns($columns: $grid-columns) { + @for $i from 1 through $columns { + .col-xs-#{$i}, .col-sm-#{$i}, .col-md-#{$i}, .col-lg-#{$i}, .col-xl-#{$i} { + @extend %twbs-grid-column; + } } } +@mixin float-grid-columns($class, $columns: $grid-columns) { + @for $i from 1 through $columns { + .col-#{$class}-#{$i} { + @extend %twbs-grid-column-float; + } + } +} -@mixin calc-grid-column($index, $class, $type) { +@mixin calc-grid-column($index, $class, $type, $columns: $grid-columns) { @if ($type == width) and ($index > 0) { .col-#{$class}-#{$index} { - width: percentage(($index / $grid-columns)); + width: percentage($index / $columns); } } - @if ($type == push) and ($index > 0) { + @if $type == push { .col-#{$class}-push-#{$index} { - left: percentage(($index / $grid-columns)); - } - } - @if ($type == push) and ($index == 0) { - .col-#{$class}-push-0 { - left: auto; + left: if($index > 0, percentage($index / $columns), auto); } } - @if ($type == pull) and ($index > 0) { + @if $type == pull { .col-#{$class}-pull-#{$index} { - right: percentage(($index / $grid-columns)); - } - } - @if ($type == pull) and ($index == 0) { - .col-#{$class}-pull-0 { - right: auto; + right: if($index > 0, percentage($index / $columns), auto); } } - @if ($type == offset) { + @if $type == offset { .col-#{$class}-offset-#{$index} { - margin-left: percentage(($index / $grid-columns)); + margin-left: percentage($index / $columns); } } } -// [converter] This is defined recursively in LESS, but Sass supports real loops -@mixin loop-grid-columns($columns, $class, $type) { +// Create grid for specific class +@mixin make-grid($class, $columns: $grid-columns) { + @include float-grid-columns($class); @for $i from 0 through $columns { - @include calc-grid-column($i, $class, $type); + @include calc-grid-column($i, $class, width, $columns); + @include calc-grid-column($i, $class, push, $columns); + @include calc-grid-column($i, $class, pull, $columns); + @include calc-grid-column($i, $class, offset, $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 |
