1
0
mirror of https://github.com/twbs/bootstrap.git synced 2025-08-13 17:14:04 +02:00

Change breakpoint-max implementation

- The `media-breakpoint-down()` uses the breakpoint itself instead of the next breakpoint. Use `media-breakpoint-down(lg)` instead of `media-breakpoint-down(md)` to target viewports smaller than the `lg` breakpoint.
- The `media-breakpoint-between()` mixin's second parameter also uses the breakpoint itself instead of the next breakpoint. Use `media-between(sm, lg)` instead of `media-breakpoint-between(sm, md)` to target viewports between the `sm` and `lg` breakpoints.
This commit is contained in:
Martijn Cuppens
2020-04-18 13:02:26 +02:00
committed by Mark Otto
parent aee711bfa9
commit 7e28764e67
8 changed files with 31 additions and 23 deletions

View File

@@ -203,8 +203,8 @@
} }
@each $breakpoint in map-keys($grid-breakpoints) { @each $breakpoint in map-keys($grid-breakpoints) {
$next-breakpoint: breakpoint-next($breakpoint); $infix: breakpoint-infix($breakpoint, $grid-breakpoints);
$postfix: if(breakpoint-max($breakpoint, $grid-breakpoints) == null, "", "-#{$next-breakpoint}-down"); $postfix: if($infix != "", $infix + "-down", "");
@include media-breakpoint-down($breakpoint) { @include media-breakpoint-down($breakpoint) {
.modal-fullscreen#{$postfix} { .modal-fullscreen#{$postfix} {

View File

@@ -140,8 +140,7 @@
// size of where your table will overflow. // size of where your table will overflow.
@each $breakpoint in map-keys($grid-breakpoints) { @each $breakpoint in map-keys($grid-breakpoints) {
$next: breakpoint-next($breakpoint, $grid-breakpoints); $infix: breakpoint-infix($breakpoint, $grid-breakpoints);
$infix: breakpoint-infix($next, $grid-breakpoints);
@include media-breakpoint-down($breakpoint) { @include media-breakpoint-down($breakpoint) {
.table-responsive#{$infix} { .table-responsive#{$infix} {

View File

@@ -31,18 +31,18 @@
@return if($min != 0, $min, null); @return if($min != 0, $min, null);
} }
// Maximum breakpoint width. Null for the largest (last) breakpoint. // Maximum breakpoint width.
// The maximum value is calculated as the minimum of the next one less 0.02px // The maximum value is reduced by 0.02px to work around the limitations of
// to work around the limitations of `min-` and `max-` prefixes and viewports with fractional widths. // `min-` and `max-` prefixes and viewports with fractional widths.
// See https://www.w3.org/TR/mediaqueries-4/#mq-min-max // See https://www.w3.org/TR/mediaqueries-4/#mq-min-max
// Uses 0.02px rather than 0.01px to work around a current rounding bug in Safari. // Uses 0.02px rather than 0.01px to work around a current rounding bug in Safari.
// See https://bugs.webkit.org/show_bug.cgi?id=178261 // See https://bugs.webkit.org/show_bug.cgi?id=178261
// //
// >> breakpoint-max(sm, (xs: 0, sm: 576px, md: 768px, lg: 992px, xl: 1200px)) // >> breakpoint-max(md, (xs: 0, sm: 576px, md: 768px, lg: 992px, xl: 1200px))
// 767.98px // 767.98px
@function breakpoint-max($name, $breakpoints: $grid-breakpoints) { @function breakpoint-max($name, $breakpoints: $grid-breakpoints) {
$next: breakpoint-next($name, $breakpoints); $max: map-get($breakpoints, $name);
@return if($next, breakpoint-min($next, $breakpoints) - .02, null); @return if($max and $max > 0, $max - .02, null);
} }
// Returns a blank string if smallest breakpoint, otherwise returns the name with a dash in front. // Returns a blank string if smallest breakpoint, otherwise returns the name with a dash in front.
@@ -108,7 +108,7 @@
// Makes the @content apply only to the given breakpoint, not viewports any wider or narrower. // Makes the @content apply only to the given breakpoint, not viewports any wider or narrower.
@mixin media-breakpoint-only($name, $breakpoints: $grid-breakpoints) { @mixin media-breakpoint-only($name, $breakpoints: $grid-breakpoints) {
$min: breakpoint-min($name, $breakpoints); $min: breakpoint-min($name, $breakpoints);
$max: breakpoint-max($name, $breakpoints); $max: breakpoint-max(breakpoint-next($name, $breakpoints));
@if $min != null and $max != null { @if $min != null and $max != null {
@media (min-width: $min) and (max-width: $max) { @media (min-width: $min) and (max-width: $max) {

View File

@@ -29,7 +29,7 @@
margin-bottom: 1.5rem; margin-bottom: 1.5rem;
@include font-size(.875rem); @include font-size(.875rem);
@include media-breakpoint-down(md) { @include media-breakpoint-down(lg) {
display: block; display: block;
overflow-x: auto; overflow-x: auto;

View File

@@ -2,7 +2,7 @@
padding: .625rem 0; padding: .625rem 0;
background-color: $bd-purple-bright; background-color: $bd-purple-bright;
@include media-breakpoint-down(md) { @include media-breakpoint-down(lg) {
.navbar-nav-scroll { .navbar-nav-scroll {
width: 100%; width: 100%;

View File

@@ -26,7 +26,7 @@
} }
.bd-search { .bd-search {
@include media-breakpoint-down(sm) { @include media-breakpoint-down(md) {
width: 100%; width: 100%;
} }

View File

@@ -127,12 +127,12 @@ These Sass mixins translate in our compiled CSS using the values declared in our
We occasionally use media queries that go in the other direction (the given screen size *or smaller*): We occasionally use media queries that go in the other direction (the given screen size *or smaller*):
{{< highlight scss >}} {{< highlight scss >}}
@include media-breakpoint-down(xs) { ... } // No media query necessary for xs breakpoint as it's effectively `@media (max-width: 0) { ... }`
@include media-breakpoint-down(sm) { ... } @include media-breakpoint-down(sm) { ... }
@include media-breakpoint-down(md) { ... } @include media-breakpoint-down(md) { ... }
@include media-breakpoint-down(lg) { ... } @include media-breakpoint-down(lg) { ... }
@include media-breakpoint-down(xl) { ... } @include media-breakpoint-down(xl) { ... }
// No media query necessary for xxl breakpoint as it has no upper bound on its width @include media-breakpoint-down(xxl) { ... }
// Example: Style from medium breakpoint and down // Example: Style from medium breakpoint and down
@include media-breakpoint-down(md) { @include media-breakpoint-down(md) {
@@ -181,18 +181,25 @@ There are also media queries and mixins for targeting a single segment of screen
@include media-breakpoint-only(xxl) { ... } @include media-breakpoint-only(xxl) { ... }
{{< /highlight >}} {{< /highlight >}}
For example the `@include media-breakpoint-only(md) { ... }` will result in :
{{< highlight scss >}}
@media (min-width: 768px) and (max-width: 991.98px) { ... }
{{< /highlight >}}
### Between breakpoints
Similarly, media queries may span multiple breakpoint widths: Similarly, media queries may span multiple breakpoint widths:
{{< highlight scss >}}
@include media-breakpoint-between(md, xl) { ... }
{{< /highlight >}}
Which results in:
{{< highlight scss >}} {{< highlight scss >}}
// Example // Example
// Apply styles starting from medium devices and up to extra large devices // Apply styles starting from medium devices and up to extra large devices
@media (min-width: 768px) and (max-width: 1199.98px) { ... } @media (min-width: 768px) and (max-width: 1199.98px) { ... }
{{< /highlight >}} {{< /highlight >}}
### Between breakpoints
The Sass mixin for targeting the same screen size range would be:
{{< highlight scss >}}
@include media-breakpoint-between(md, xl) { ... }
{{< /highlight >}}

View File

@@ -48,6 +48,8 @@ Changes to our source Sass files and compiled CSS.
- `$yiq-text-dark` and `$yiq-text-light` are respectively renamed to `$color-contrast-dark` and `$color-contrast-light`. - `$yiq-text-dark` and `$yiq-text-light` are respectively renamed to `$color-contrast-dark` and `$color-contrast-light`.
- Linear gradients are simplified when gradients are enabled and therefore, `gradient-bg()` now only accepts an optional `$color` parameter. - Linear gradients are simplified when gradients are enabled and therefore, `gradient-bg()` now only accepts an optional `$color` parameter.
- The `bg-gradient-variant()` mixin is removed since the `.bg-gradient` class can now be used to add gradients to elements instead of the `.bg-gradient-*` classes. - The `bg-gradient-variant()` mixin is removed since the `.bg-gradient` class can now be used to add gradients to elements instead of the `.bg-gradient-*` classes.
- The `media-breakpoint-down()` uses the breakpoint itself instead of the next breakpoint. Use `media-breakpoint-down(lg)` instead of `media-breakpoint-down(md)` to target viewports smaller than the `lg` breakpoint.
- The `media-breakpoint-between()` mixin's second parameter also uses the breakpoint itself instead of the next breakpoint. Use `media-between(sm, lg)` instead of `media-breakpoint-between(sm, md)` to target viewports between the `sm` and `lg` breakpoints.
## JavaScript ## JavaScript