_grids.scss
163 lines
| 1 | /** |
| 2 | * Media of at least the minimum breakpoint width. No query for the smallest breakpoint. |
| 3 | * Makes the @content apply to the given breakpoint and wider. |
| 4 | **/ |
| 5 | @mixin media-breakpoint-up($name, $breakpoints: $grid-breakpoints) { |
| 6 | $min: breakpoint-min($name, $breakpoints); |
| 7 | @if $min { |
| 8 | @media (min-width: $min) { |
| 9 | @content; |
| 10 | } |
| 11 | } |
| 12 | @else { |
| 13 | @content; |
| 14 | } |
| 15 | } |
| 16 | |
| 17 | /** |
| 18 | * Grid system |
| 19 | * |
| 20 | * Generate semantic grid columns with these mixins. |
| 21 | **/ |
| 22 | @mixin create-container($gutter: $grid-gutter) { |
| 23 | width: 100%; |
| 24 | padding-right: $gutter; |
| 25 | padding-left: $gutter; |
| 26 | margin-right: auto; |
| 27 | margin-left: auto; |
| 28 | |
| 29 | *, |
| 30 | ::before, |
| 31 | ::after { |
| 32 | box-sizing: border-box; |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | // For each breakpoint, define the maximum width of the container in a media query |
| 37 | @mixin create-container-max-widths($max-widths: $container-max-widths, $breakpoints: $grid-breakpoints) { |
| 38 | @each $breakpoint, $container-max-width in $max-widths { |
| 39 | @include media-breakpoint-up($breakpoint, $breakpoints) { |
| 40 | max-width: $container-max-width; |
| 41 | } |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | @mixin create-row($gutter: $grid-gutter) { |
| 46 | display: flex; |
| 47 | flex-wrap: wrap; |
| 48 | margin-right: -$gutter; |
| 49 | margin-left: -$gutter; |
| 50 | } |
| 51 | |
| 52 | @mixin make-col-auto() { |
| 53 | flex: 0 0 auto; |
| 54 | width: auto; |
| 55 | } |
| 56 | |
| 57 | @mixin make-col($size, $columns: $grid-columns) { |
| 58 | flex: 0 0 percentage($size / $columns); |
| 59 | // Add a `max-width` to ensure content within each column does not blow out |
| 60 | // the width of the column. Applies to IE10+ and Firefox. Chrome and Safari |
| 61 | // do not appear to require this. |
| 62 | max-width: percentage($size / $columns); |
| 63 | } |
| 64 | |
| 65 | @mixin make-col-offset($size, $columns: $grid-columns) { |
| 66 | $num: $size / $columns; |
| 67 | margin-left: if($num == 0, 0, percentage($num)); |
| 68 | } |
| 69 | |
| 70 | // Row columns |
| 71 | // |
| 72 | // Specify on a parent element(e.g., .row) to force immediate children into NN |
| 73 | // numberof columns. Supports wrapping to new lines, but does not do a Masonry |
| 74 | // style grid. |
| 75 | @mixin row-cols($count) { |
| 76 | & > * { |
| 77 | flex: 0 0 auto; |
| 78 | width: 100% / $count; |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | @mixin make-grid-columns($columns: $grid-columns, $gutter: $grid-gutter, $breakpoints: $grid-breakpoints) { |
| 83 | %grid-column { |
| 84 | position: relative; |
| 85 | width: 100%; |
| 86 | padding-right: $gutter; |
| 87 | padding-left: $gutter; |
| 88 | } |
| 89 | |
| 90 | @each $breakpoint in map-keys($breakpoints) { |
| 91 | $infix: breakpoint-infix($breakpoint, $breakpoints); |
| 92 | |
| 93 | @if $columns > 0 { |
| 94 | // Allow columns to stretch full width below their breakpoints |
| 95 | @for $i from 1 through $columns { |
| 96 | .evf-col#{$infix}-#{$i} { |
| 97 | @extend %grid-column; |
| 98 | } |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | .evf-col#{$infix}, |
| 103 | .evf-col#{$infix}-auto { |
| 104 | @extend %grid-column; |
| 105 | } |
| 106 | |
| 107 | @include media-breakpoint-up($breakpoint, $breakpoints) { |
| 108 | // Provide basic `.col-{bp}` classes for equal-width flexbox columns |
| 109 | .evf-col#{$infix} { |
| 110 | flex: 1 0 0%; // Flexbugs #4: https://github.com/philipwalton/flexbugs#flexbug-4 |
| 111 | } |
| 112 | |
| 113 | .evf-row-cols#{$infix}-auto > * { |
| 114 | @include make-col-auto(); |
| 115 | } |
| 116 | |
| 117 | @if $grid-row-columns > 0 { |
| 118 | @for $i from 1 through $grid-row-columns { |
| 119 | .evf-row-cols#{$infix}-#{$i} { |
| 120 | @include row-cols($i); |
| 121 | } |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | .evf-col#{$infix}-auto { |
| 126 | @include make-col-auto(); |
| 127 | } |
| 128 | |
| 129 | @if $columns > 0 { |
| 130 | @for $i from 1 through $columns { |
| 131 | .evf-col#{$infix}-#{$i} { |
| 132 | @include make-col($i, $columns); |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | // `$columns - 1` because offsetting by the width of an entire row isn't possible |
| 137 | @for $i from 0 through ($columns - 1) { |
| 138 | @if not ($infix == '' and $i == 0) { // Avoid emitting useless .offset-0 |
| 139 | .evf-offset#{$infix}-#{$i} { |
| 140 | @include make-col-offset($i, $columns); |
| 141 | } |
| 142 | } |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | // Gutters |
| 147 | // |
| 148 | // Make use of `.g-*`, `.gx-*` or `.gy-*` utilities to change spacing between the columns. |
| 149 | @each $key, $value in $grid-spacers { |
| 150 | .evf-g#{$infix}-#{$key}, |
| 151 | .evf-gx#{$infix}-#{$key} { |
| 152 | --bs-gutter-x: #{$value}; |
| 153 | } |
| 154 | |
| 155 | .evf-g#{$infix}-#{$key}, |
| 156 | .evf-gy#{$infix}-#{$key} { |
| 157 | --bs-gutter-y: #{$value}; |
| 158 | } |
| 159 | } |
| 160 | } |
| 161 | } |
| 162 | } |
| 163 |