mirror of
https://github.com/twbs/bootstrap.git
synced 2025-08-11 08:04:59 +02:00
Refactor grid-framework followup
* Split up calc-grid-column, generate selectors in make-grid * Iterate over $grid-breakpoints and (pull, push, offset)
This commit is contained in:
@@ -294,7 +294,7 @@ $screen-xs-max: ($screen-sm-min - .1);
|
|||||||
//== Grid system
|
//== Grid system
|
||||||
//
|
//
|
||||||
//## Define your custom responsive grid.
|
//## Define your custom responsive grid.
|
||||||
|
$grid-breakpoints: (xs sm md lg xl);
|
||||||
//** Number of columns in the grid.
|
//** Number of columns in the grid.
|
||||||
$grid-columns: 12;
|
$grid-columns: 12;
|
||||||
//** Padding between columns. Gets divided in half for the left and right.
|
//** Padding between columns. Gets divided in half for the left and right.
|
||||||
|
@@ -3,7 +3,9 @@
|
|||||||
// 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`.
|
||||||
|
|
||||||
%twbs-grid-column {
|
// Common properties for all breakpoints
|
||||||
|
@mixin make-grid-columns($columns: $grid-columns, $breakpoints: $grid-breakpoints) {
|
||||||
|
%grid-column {
|
||||||
position: relative;
|
position: relative;
|
||||||
// Prevent columns from collapsing when empty
|
// Prevent columns from collapsing when empty
|
||||||
min-height: 1px;
|
min-height: 1px;
|
||||||
@@ -11,57 +13,59 @@
|
|||||||
padding-left: ($grid-gutter-width / 2);
|
padding-left: ($grid-gutter-width / 2);
|
||||||
padding-right: ($grid-gutter-width / 2);
|
padding-right: ($grid-gutter-width / 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
%twbs-grid-column-float {
|
|
||||||
float: left
|
|
||||||
}
|
|
||||||
|
|
||||||
@mixin make-grid-columns($columns: $grid-columns) {
|
|
||||||
@for $i from 1 through $columns {
|
@for $i from 1 through $columns {
|
||||||
.col-xs-#{$i}, .col-sm-#{$i}, .col-md-#{$i}, .col-lg-#{$i}, .col-xl-#{$i} {
|
@each $breakpoint in $breakpoints {
|
||||||
@extend %twbs-grid-column;
|
.col-#{$breakpoint}-#{$i} {
|
||||||
|
@extend %grid-column;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@mixin float-grid-columns($class, $columns: $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;
|
||||||
|
}
|
||||||
@for $i from 1 through $columns {
|
@for $i from 1 through $columns {
|
||||||
.col-#{$class}-#{$i} {
|
.col-#{$breakpoint}-#{$i} {
|
||||||
@extend %twbs-grid-column-float;
|
@extend %grid-column-float-#{$breakpoint};
|
||||||
|
@include grid-column-width($i, $columns);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@each $modifier in (pull, push, offset) {
|
||||||
|
@for $i from 0 through $columns {
|
||||||
|
.col-#{$breakpoint}-#{$modifier}-#{$i} {
|
||||||
|
@include grid-column-modifier($modifier, $i, $columns)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@mixin calc-grid-column($index, $class, $type, $columns: $grid-columns) {
|
@mixin grid-column-width($index, $columns) {
|
||||||
@if ($type == width) and ($index > 0) {
|
|
||||||
.col-#{$class}-#{$index} {
|
|
||||||
width: percentage($index / $columns);
|
width: percentage($index / $columns);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@if $type == push {
|
@mixin grid-column-push($index, $columns) {
|
||||||
.col-#{$class}-push-#{$index} {
|
|
||||||
left: if($index > 0, percentage($index / $columns), auto);
|
left: if($index > 0, percentage($index / $columns), auto);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@if $type == pull {
|
@mixin grid-column-pull($index, $columns) {
|
||||||
.col-#{$class}-pull-#{$index} {
|
|
||||||
right: if($index > 0, percentage($index / $columns), auto);
|
right: if($index > 0, percentage($index / $columns), auto);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@if $type == offset {
|
@mixin grid-column-offset($index, $columns) {
|
||||||
.col-#{$class}-offset-#{$index} {
|
|
||||||
margin-left: percentage($index / $columns);
|
margin-left: percentage($index / $columns);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create grid for specific class
|
// Work around the lack of dynamic mixin @include support (https://github.com/sass/sass/issues/626)
|
||||||
@mixin make-grid($class, $columns: $grid-columns) {
|
@mixin grid-column-modifier($type, $index, $columns) {
|
||||||
@include float-grid-columns($class);
|
@if $type == push {
|
||||||
@for $i from 0 through $columns {
|
@include grid-column-push($index, $columns);
|
||||||
@include calc-grid-column($i, $class, width, $columns);
|
} @else if $type == pull {
|
||||||
@include calc-grid-column($i, $class, push, $columns);
|
@include grid-column-pull($index, $columns);
|
||||||
@include calc-grid-column($i, $class, pull, $columns);
|
} @else if $type == offset {
|
||||||
@include calc-grid-column($i, $class, offset, $columns);
|
@include grid-column-offset($index, $columns);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user