2014-12-20 10:03:30 -05:00
|
|
|
// Breakpoint viewport sizes and media queries.
|
|
|
|
//
|
|
|
|
// Breakpoints are defined as a map of (name: minimum width), order from small to large:
|
|
|
|
//
|
2022-04-20 10:08:55 -04:00
|
|
|
// (xs: 0, sm: 576px, md: 768px, lg: 992px, xl: 1200px, xxl: 1400px)
|
2014-12-20 10:03:30 -05:00
|
|
|
//
|
|
|
|
// The map defined in the `$grid-breakpoints` global variable is used as the `$breakpoints` argument by default.
|
|
|
|
|
|
|
|
// Name of the next breakpoint, or null for the last breakpoint.
|
|
|
|
//
|
|
|
|
// >> breakpoint-next(sm)
|
|
|
|
// md
|
2022-04-20 10:08:55 -04:00
|
|
|
// >> breakpoint-next(sm, (xs: 0, sm: 576px, md: 768px, lg: 992px, xl: 1200px, xxl: 1400px))
|
2014-12-20 10:03:30 -05:00
|
|
|
// md
|
2022-04-20 10:08:55 -04:00
|
|
|
// >> breakpoint-next(sm, $breakpoint-names: (xs sm md lg xl xxl))
|
2014-12-20 10:03:30 -05:00
|
|
|
// md
|
|
|
|
@function breakpoint-next($name, $breakpoints: $grid-breakpoints, $breakpoint-names: map-keys($breakpoints)) {
|
|
|
|
$n: index($breakpoint-names, $name);
|
2019-06-17 02:00:36 -04:00
|
|
|
@if not $n {
|
|
|
|
@error "breakpoint `#{$name}` not found in `#{$breakpoints}`";
|
|
|
|
}
|
|
|
|
@return if($n < length($breakpoint-names), nth($breakpoint-names, $n + 1), null);
|
2014-12-20 10:03:30 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Minimum breakpoint width. Null for the smallest (first) breakpoint.
|
|
|
|
//
|
2022-04-20 10:08:55 -04:00
|
|
|
// >> breakpoint-min(sm, (xs: 0, sm: 576px, md: 768px, lg: 992px, xl: 1200px, xxl: 1400px))
|
2016-12-04 19:46:07 -05:00
|
|
|
// 576px
|
2014-12-20 10:03:30 -05:00
|
|
|
@function breakpoint-min($name, $breakpoints: $grid-breakpoints) {
|
|
|
|
$min: map-get($breakpoints, $name);
|
|
|
|
@return if($min != 0, $min, null);
|
|
|
|
}
|
|
|
|
|
2020-04-18 07:02:26 -04:00
|
|
|
// Maximum breakpoint width.
|
|
|
|
// The maximum value is reduced by 0.02px to work around the limitations of
|
|
|
|
// `min-` and `max-` prefixes and viewports with fractional widths.
|
2017-11-20 05:13:37 -05:00
|
|
|
// See https://www.w3.org/TR/mediaqueries-4/#mq-min-max
|
2018-01-03 02:42:03 -05:00
|
|
|
// 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
|
2014-12-20 10:03:30 -05:00
|
|
|
//
|
2022-04-20 10:08:55 -04:00
|
|
|
// >> breakpoint-max(md, (xs: 0, sm: 576px, md: 768px, lg: 992px, xl: 1200px, xxl: 1400px))
|
2018-01-03 02:42:03 -05:00
|
|
|
// 767.98px
|
2014-12-20 10:03:30 -05:00
|
|
|
@function breakpoint-max($name, $breakpoints: $grid-breakpoints) {
|
2020-04-18 07:02:26 -04:00
|
|
|
$max: map-get($breakpoints, $name);
|
|
|
|
@return if($max and $max > 0, $max - .02, null);
|
2014-12-20 10:03:30 -05:00
|
|
|
}
|
|
|
|
|
2018-07-09 20:59:22 -04:00
|
|
|
// Returns a blank string if smallest breakpoint, otherwise returns the name with a dash in front.
|
2016-11-28 16:23:59 -05:00
|
|
|
// Useful for making responsive utilities.
|
|
|
|
//
|
2022-04-20 10:08:55 -04:00
|
|
|
// >> breakpoint-infix(xs, (xs: 0, sm: 576px, md: 768px, lg: 992px, xl: 1200px, xxl: 1400px))
|
2016-11-28 16:23:59 -05:00
|
|
|
// "" (Returns a blank string)
|
2022-04-20 10:08:55 -04:00
|
|
|
// >> breakpoint-infix(sm, (xs: 0, sm: 576px, md: 768px, lg: 992px, xl: 1200px, xxl: 1400px))
|
2016-11-28 16:23:59 -05:00
|
|
|
// "-sm"
|
|
|
|
@function breakpoint-infix($name, $breakpoints: $grid-breakpoints) {
|
|
|
|
@return if(breakpoint-min($name, $breakpoints) == null, "", "-#{$name}");
|
|
|
|
}
|
|
|
|
|
2014-12-20 10:03:30 -05:00
|
|
|
// Media of at least the minimum breakpoint width. No query for the smallest breakpoint.
|
2014-12-29 16:37:20 -05:00
|
|
|
// Makes the @content apply to the given breakpoint and wider.
|
|
|
|
@mixin media-breakpoint-up($name, $breakpoints: $grid-breakpoints) {
|
2014-12-20 10:03:30 -05:00
|
|
|
$min: breakpoint-min($name, $breakpoints);
|
|
|
|
@if $min {
|
|
|
|
@media (min-width: $min) {
|
|
|
|
@content;
|
|
|
|
}
|
|
|
|
} @else {
|
|
|
|
@content;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Media of at most the maximum breakpoint width. No query for the largest breakpoint.
|
2014-12-29 16:37:20 -05:00
|
|
|
// Makes the @content apply to the given breakpoint and narrower.
|
|
|
|
@mixin media-breakpoint-down($name, $breakpoints: $grid-breakpoints) {
|
2014-12-20 10:03:30 -05:00
|
|
|
$max: breakpoint-max($name, $breakpoints);
|
|
|
|
@if $max {
|
|
|
|
@media (max-width: $max) {
|
|
|
|
@content;
|
|
|
|
}
|
|
|
|
} @else {
|
|
|
|
@content;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-25 15:53:14 -04:00
|
|
|
// Media that spans multiple breakpoint widths.
|
|
|
|
// Makes the @content apply between the min and max breakpoints
|
|
|
|
@mixin media-breakpoint-between($lower, $upper, $breakpoints: $grid-breakpoints) {
|
2017-08-06 21:59:14 -04:00
|
|
|
$min: breakpoint-min($lower, $breakpoints);
|
2017-03-26 01:23:40 -04:00
|
|
|
$max: breakpoint-max($upper, $breakpoints);
|
|
|
|
|
2017-10-03 00:38:59 -04:00
|
|
|
@if $min != null and $max != null {
|
|
|
|
@media (min-width: $min) and (max-width: $max) {
|
|
|
|
@content;
|
|
|
|
}
|
|
|
|
} @else if $max == null {
|
2018-01-13 02:45:21 -05:00
|
|
|
@include media-breakpoint-up($lower, $breakpoints) {
|
2017-10-03 00:38:59 -04:00
|
|
|
@content;
|
|
|
|
}
|
|
|
|
} @else if $min == null {
|
2018-01-13 02:45:21 -05:00
|
|
|
@include media-breakpoint-down($upper, $breakpoints) {
|
2017-10-03 00:38:59 -04:00
|
|
|
@content;
|
|
|
|
}
|
2015-08-25 15:53:14 -04:00
|
|
|
}
|
2015-09-02 13:09:55 -04:00
|
|
|
}
|
2016-06-09 11:07:27 -04:00
|
|
|
|
|
|
|
// Media between the breakpoint's minimum and maximum widths.
|
|
|
|
// No minimum for the smallest breakpoint, and no maximum for the largest one.
|
|
|
|
// Makes the @content apply only to the given breakpoint, not viewports any wider or narrower.
|
|
|
|
@mixin media-breakpoint-only($name, $breakpoints: $grid-breakpoints) {
|
2020-08-18 10:37:01 -04:00
|
|
|
$min: breakpoint-min($name, $breakpoints);
|
|
|
|
$next: breakpoint-next($name, $breakpoints);
|
2021-09-30 13:18:52 -04:00
|
|
|
$max: breakpoint-max($next, $breakpoints);
|
2017-03-26 01:23:40 -04:00
|
|
|
|
2017-05-04 04:54:59 -04:00
|
|
|
@if $min != null and $max != null {
|
|
|
|
@media (min-width: $min) and (max-width: $max) {
|
|
|
|
@content;
|
|
|
|
}
|
|
|
|
} @else if $max == null {
|
2018-01-13 02:45:21 -05:00
|
|
|
@include media-breakpoint-up($name, $breakpoints) {
|
2017-08-17 04:27:59 -04:00
|
|
|
@content;
|
|
|
|
}
|
2017-05-04 04:54:59 -04:00
|
|
|
} @else if $min == null {
|
2020-08-18 10:37:01 -04:00
|
|
|
@include media-breakpoint-down($next, $breakpoints) {
|
2017-08-17 04:27:59 -04:00
|
|
|
@content;
|
|
|
|
}
|
2016-06-09 11:07:27 -04:00
|
|
|
}
|
|
|
|
}
|