3 // Generate semantic grid columns with these mixins.
5 @mixin make-row($gutter: $grid-gutter-width) {
6 --#{$prefix}gutter-x: #{$gutter};
7 --#{$prefix}gutter-y: 0;
10 // TODO: Revisit calc order after https://github.com/react-bootstrap/react-bootstrap/issues/6039 is fixed
11 margin-top: calc(-1 * var(--#{$prefix}gutter-y)); // stylelint-disable-line function-disallowed-list
12 margin-right: calc(-.5 * var(--#{$prefix}gutter-x)); // stylelint-disable-line function-disallowed-list
13 margin-left: calc(-.5 * var(--#{$prefix}gutter-x)); // stylelint-disable-line function-disallowed-list
16 @mixin make-col-ready() {
17 // Add box sizing if only the grid is loaded
18 box-sizing: if(variable-exists(include-column-box-sizing) and $include-column-box-sizing, border-box, null);
19 // Prevent columns from becoming too narrow when at smaller grid tiers by
20 // always setting `width: 100%;`. This works because we set the width
21 // later on to override this initial width.
24 max-width: 100%; // Prevent `.col-auto`, `.col` (& responsive variants) from breaking out the grid
25 padding-right: calc(var(--#{$prefix}gutter-x) * .5); // stylelint-disable-line function-disallowed-list
26 padding-left: calc(var(--#{$prefix}gutter-x) * .5); // stylelint-disable-line function-disallowed-list
27 margin-top: var(--#{$prefix}gutter-y);
30 @mixin make-col($size: false, $columns: $grid-columns) {
33 width: percentage(divide($size, $columns));
41 @mixin make-col-auto() {
46 @mixin make-col-offset($size, $columns: $grid-columns) {
47 $num: divide($size, $columns);
48 margin-left: if($num == 0, 0, percentage($num));
53 // Specify on a parent element(e.g., .row) to force immediate children into NN
54 // number of columns. Supports wrapping to new lines, but does not do a Masonry
56 @mixin row-cols($count) {
59 width: divide(100%, $count);
63 // Framework grid generation
65 // Used only by Bootstrap to generate the correct number of grid classes given
66 // any value of `$grid-columns`.
68 @mixin make-grid-columns($columns: $grid-columns, $gutter: $grid-gutter-width, $breakpoints: $grid-breakpoints) {
69 @each $breakpoint in map-keys($breakpoints) {
70 $infix: breakpoint-infix($breakpoint, $breakpoints);
72 @include media-breakpoint-up($breakpoint, $breakpoints) {
73 // Provide basic `.col-{bp}` classes for equal-width flexbox columns
75 flex: 1 0 0%; // Flexbugs #4: https://github.com/philipwalton/flexbugs#flexbug-4
78 .row-cols#{$infix}-auto > * {
79 @include make-col-auto();
82 @if $grid-row-columns > 0 {
83 @for $i from 1 through $grid-row-columns {
84 .row-cols#{$infix}-#{$i} {
85 @include row-cols($i);
91 @include make-col-auto();
95 @for $i from 1 through $columns {
97 @include make-col($i, $columns);
101 // `$columns - 1` because offsetting by the width of an entire row isn't possible
102 @for $i from 0 through ($columns - 1) {
103 @if not ($infix == "" and $i == 0) { // Avoid emitting useless .offset-0
104 .offset#{$infix}-#{$i} {
105 @include make-col-offset($i, $columns);
113 // Make use of `.g-*`, `.gx-*` or `.gy-*` utilities to change spacing between the columns.
114 @each $key, $value in $gutters {
116 .gx#{$infix}-#{$key} {
117 --#{$prefix}gutter-x: #{$value};
121 .gy#{$infix}-#{$key} {
122 --#{$prefix}gutter-y: #{$value};
129 @mixin make-cssgrid($columns: $grid-columns, $breakpoints: $grid-breakpoints) {
130 @each $breakpoint in map-keys($breakpoints) {
131 $infix: breakpoint-infix($breakpoint, $breakpoints);
133 @include media-breakpoint-up($breakpoint, $breakpoints) {
135 @for $i from 1 through $columns {
136 .g-col#{$infix}-#{$i} {
137 grid-column: auto / span $i;
141 // Start with `1` because `0` is and invalid value.
142 // Ends with `$columns - 1` because offsetting by the width of an entire row isn't possible.
143 @for $i from 1 through ($columns - 1) {
144 .g-start#{$infix}-#{$i} {
145 grid-column-start: $i;