mirror of
https://github.com/twbs/bootstrap.git
synced 2025-08-18 11:21:23 +02:00
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
This commit is contained in:
@@ -3,79 +3,65 @@
|
|||||||
// Used only by Bootstrap to generate the correct number of grid classes given
|
// Used only by Bootstrap to generate the correct number of grid classes given
|
||||||
// any value of `$grid-columns`.
|
// any value of `$grid-columns`.
|
||||||
|
|
||||||
// [converter] This is defined recursively in LESS, but Sass supports real loops
|
%twbs-grid-column {
|
||||||
@mixin make-grid-columns($i: 1, $list: ".col-xs-#{$i}, .col-sm-#{$i}, .col-md-#{$i}, .col-lg-#{$i}, .col-xl-#{$i}") {
|
position: relative;
|
||||||
@for $i from (1 + 1) through $grid-columns {
|
// Prevent columns from collapsing when empty
|
||||||
$list: "#{$list}, .col-xs-#{$i}, .col-sm-#{$i}, .col-md-#{$i}, .col-lg-#{$i}, .col-xl-#{$i}";
|
min-height: 1px;
|
||||||
}
|
// Inner gutter via padding
|
||||||
#{$list} {
|
padding-left: ($grid-gutter-width / 2);
|
||||||
position: relative;
|
padding-right: ($grid-gutter-width / 2);
|
||||||
// Prevent columns from collapsing when empty
|
}
|
||||||
min-height: 1px;
|
|
||||||
// Inner gutter via padding
|
%twbs-grid-column-float {
|
||||||
padding-left: ($grid-gutter-width / 2);
|
float: left
|
||||||
padding-right: ($grid-gutter-width / 2);
|
}
|
||||||
|
|
||||||
|
@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) {
|
||||||
// [converter] This is defined recursively in LESS, but Sass supports real loops
|
@for $i from 1 through $columns {
|
||||||
@mixin float-grid-columns($class, $i: 1, $list: ".col-#{$class}-#{$i}") {
|
.col-#{$class}-#{$i} {
|
||||||
@for $i from (1 + 1) through $grid-columns {
|
@extend %twbs-grid-column-float;
|
||||||
$list: "#{$list}, .col-#{$class}-#{$i}";
|
}
|
||||||
}
|
|
||||||
#{$list} {
|
|
||||||
float: left;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@mixin calc-grid-column($index, $class, $type, $columns: $grid-columns) {
|
||||||
@mixin calc-grid-column($index, $class, $type) {
|
|
||||||
@if ($type == width) and ($index > 0) {
|
@if ($type == width) and ($index > 0) {
|
||||||
.col-#{$class}-#{$index} {
|
.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} {
|
.col-#{$class}-push-#{$index} {
|
||||||
left: percentage(($index / $grid-columns));
|
left: if($index > 0, percentage($index / $columns), auto);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@if ($type == push) and ($index == 0) {
|
@if $type == pull {
|
||||||
.col-#{$class}-push-0 {
|
|
||||||
left: auto;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@if ($type == pull) and ($index > 0) {
|
|
||||||
.col-#{$class}-pull-#{$index} {
|
.col-#{$class}-pull-#{$index} {
|
||||||
right: percentage(($index / $grid-columns));
|
right: if($index > 0, percentage($index / $columns), auto);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@if ($type == pull) and ($index == 0) {
|
@if $type == offset {
|
||||||
.col-#{$class}-pull-0 {
|
|
||||||
right: auto;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@if ($type == offset) {
|
|
||||||
.col-#{$class}-offset-#{$index} {
|
.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) {
|
|
||||||
@for $i from 0 through $columns {
|
|
||||||
@include calc-grid-column($i, $class, $type);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Create grid for specific class
|
// Create grid for specific class
|
||||||
@mixin make-grid($class) {
|
@mixin make-grid($class, $columns: $grid-columns) {
|
||||||
@include float-grid-columns($class);
|
@include float-grid-columns($class);
|
||||||
@include loop-grid-columns($grid-columns, $class, width);
|
@for $i from 0 through $columns {
|
||||||
@include loop-grid-columns($grid-columns, $class, pull);
|
@include calc-grid-column($i, $class, width, $columns);
|
||||||
@include loop-grid-columns($grid-columns, $class, push);
|
@include calc-grid-column($i, $class, push, $columns);
|
||||||
@include loop-grid-columns($grid-columns, $class, offset);
|
@include calc-grid-column($i, $class, pull, $columns);
|
||||||
}
|
@include calc-grid-column($i, $class, offset, $columns);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user