|
1 |
| -// Breakpoint viewport sizes and media queries. |
| 1 | +// Breakpoint viewport sizes and container queries. |
2 | 2 | //
|
3 | 3 | // Breakpoints are defined as a map of (name: minimum width), order from small to large:
|
4 | 4 | //
|
5 | 5 | // (xs: 0, sm: 576px, md: 768px, lg: 992px, xl: 1200px, xxl: 1400px)
|
6 | 6 | //
|
7 | 7 | // The map defined in the `$grid-breakpoints` global variable is used as the `$breakpoints` argument by default.
|
8 | 8 |
|
| 9 | +// Set the document root element as the default container to maximize the available viewport width. |
| 10 | +// This should allow in most cases to keep backwards compatibility with the previous Media Query implementation. |
| 11 | +html { |
| 12 | + container-type: inline-size; |
| 13 | +} |
| 14 | + |
| 15 | +// Applying this class to an element makes Bootstrap's responsive utilities reference the container's size rather than the viewport's. |
| 16 | +.breakpoint-container { |
| 17 | + container-type: inline-size; |
| 18 | +} |
| 19 | + |
9 | 20 | // Name of the next breakpoint, or null for the last breakpoint.
|
10 | 21 | //
|
11 | 22 | // >> breakpoint-next(sm)
|
|
56 | 67 | @return if(breakpoint-min($name, $breakpoints) == null, "", "-#{$name}");
|
57 | 68 | }
|
58 | 69 |
|
59 |
| -// Media of at least the minimum breakpoint width. No query for the smallest breakpoint. |
| 70 | +// Container query of at least the minimum breakpoint width. No query for the smallest breakpoint. |
60 | 71 | // Makes the @content apply to the given breakpoint and wider.
|
61 |
| -@mixin media-breakpoint-up($name, $breakpoints: $grid-breakpoints) { |
| 72 | +@mixin container-breakpoint-up($name, $breakpoints: $grid-breakpoints) { |
62 | 73 | $min: breakpoint-min($name, $breakpoints);
|
63 | 74 | @if $min {
|
64 |
| - @media (min-width: $min) { |
| 75 | + @container (min-width: #{$min}) { |
65 | 76 | @content;
|
66 | 77 | }
|
67 | 78 | } @else {
|
68 | 79 | @content;
|
69 | 80 | }
|
70 | 81 | }
|
71 | 82 |
|
72 |
| -// Media of at most the maximum breakpoint width. No query for the largest breakpoint. |
| 83 | +// Container query of at most the maximum breakpoint width. No query for the largest breakpoint. |
73 | 84 | // Makes the @content apply to the given breakpoint and narrower.
|
74 |
| -@mixin media-breakpoint-down($name, $breakpoints: $grid-breakpoints) { |
| 85 | +@mixin container-breakpoint-down($name, $breakpoints: $grid-breakpoints) { |
75 | 86 | $max: breakpoint-max($name, $breakpoints);
|
76 | 87 | @if $max {
|
77 |
| - @media (max-width: $max) { |
| 88 | + @container (max-width: #{$max}) { |
78 | 89 | @content;
|
79 | 90 | }
|
80 | 91 | } @else {
|
81 | 92 | @content;
|
82 | 93 | }
|
83 | 94 | }
|
84 | 95 |
|
85 |
| -// Media that spans multiple breakpoint widths. |
| 96 | +// Container query that spans multiple breakpoint widths. |
86 | 97 | // Makes the @content apply between the min and max breakpoints
|
87 |
| -@mixin media-breakpoint-between($lower, $upper, $breakpoints: $grid-breakpoints) { |
| 98 | +@mixin container-breakpoint-between($lower, $upper, $breakpoints: $grid-breakpoints) { |
88 | 99 | $min: breakpoint-min($lower, $breakpoints);
|
89 | 100 | $max: breakpoint-max($upper, $breakpoints);
|
90 | 101 |
|
91 | 102 | @if $min != null and $max != null {
|
92 |
| - @media (min-width: $min) and (max-width: $max) { |
| 103 | + @container (min-width: #{$min}) and (max-width: #{$max}) { |
93 | 104 | @content;
|
94 | 105 | }
|
95 | 106 | } @else if $max == null {
|
96 |
| - @include media-breakpoint-up($lower, $breakpoints) { |
| 107 | + @include container-breakpoint-up($lower, $breakpoints) { |
97 | 108 | @content;
|
98 | 109 | }
|
99 | 110 | } @else if $min == null {
|
100 |
| - @include media-breakpoint-down($upper, $breakpoints) { |
| 111 | + @include container-breakpoint-down($upper, $breakpoints) { |
101 | 112 | @content;
|
102 | 113 | }
|
103 | 114 | }
|
104 | 115 | }
|
105 | 116 |
|
106 |
| -// Media between the breakpoint's minimum and maximum widths. |
| 117 | +// Container query between the breakpoint's minimum and maximum widths. |
107 | 118 | // No minimum for the smallest breakpoint, and no maximum for the largest one.
|
108 | 119 | // Makes the @content apply only to the given breakpoint, not viewports any wider or narrower.
|
109 |
| -@mixin media-breakpoint-only($name, $breakpoints: $grid-breakpoints) { |
| 120 | +@mixin container-breakpoint-only($name, $breakpoints: $grid-breakpoints) { |
110 | 121 | $min: breakpoint-min($name, $breakpoints);
|
111 | 122 | $next: breakpoint-next($name, $breakpoints);
|
112 | 123 | $max: breakpoint-max($next, $breakpoints);
|
113 | 124 |
|
114 | 125 | @if $min != null and $max != null {
|
115 |
| - @media (min-width: $min) and (max-width: $max) { |
| 126 | + @container (min-width: #{$min}) and (max-width: #{$max}) { |
116 | 127 | @content;
|
117 | 128 | }
|
118 | 129 | } @else if $max == null {
|
119 |
| - @include media-breakpoint-up($name, $breakpoints) { |
| 130 | + @include container-breakpoint-up($name, $breakpoints) { |
120 | 131 | @content;
|
121 | 132 | }
|
122 | 133 | } @else if $min == null {
|
123 |
| - @include media-breakpoint-down($next, $breakpoints) { |
| 134 | + @include container-breakpoint-down($next, $breakpoints) { |
124 | 135 | @content;
|
125 | 136 | }
|
126 | 137 | }
|
127 | 138 | }
|
| 139 | + |
| 140 | +// Aliases for the previous mixin, for backwards compatibility. |
| 141 | +@mixin media-breakpoint-up($name, $breakpoints: $grid-breakpoints) { |
| 142 | + @include container-breakpoint-up($name, $breakpoints) { |
| 143 | + @content; |
| 144 | + } |
| 145 | +} |
| 146 | + |
| 147 | +@mixin media-breakpoint-down($name, $breakpoints: $grid-breakpoints) { |
| 148 | + @include container-breakpoint-down($name, $breakpoints) { |
| 149 | + @content; |
| 150 | + } |
| 151 | +} |
| 152 | + |
| 153 | +@mixin media-breakpoint-between($lower, $upper, $breakpoints: $grid-breakpoints) { |
| 154 | + @include container-breakpoint-between($lower, $upper, $breakpoints) { |
| 155 | + @content; |
| 156 | + } |
| 157 | +} |
| 158 | + |
| 159 | +@mixin media-breakpoint-only($name, $breakpoints: $grid-breakpoints) { |
| 160 | + @include container-breakpoint-only($name, $breakpoints) { |
| 161 | + @content; |
| 162 | + } |
| 163 | +} |
0 commit comments