2014-12-20 15:03:30 +00:00
|
|
|
// Breakpoint viewport sizes and media queries.
|
|
|
|
//
|
|
|
|
// Breakpoints are defined as a map of (name: minimum width), order from small to large:
|
|
|
|
//
|
2017-01-07 15:26:21 +00:00
|
|
|
// (xs: 0, sm: 576px, md: 768px, lg: 992px, xl: 1200px)
|
2014-12-20 15:03:30 +00: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
|
2017-01-07 15:26:21 +00:00
|
|
|
// >> breakpoint-next(sm, (xs: 0, sm: 576px, md: 768px, lg: 992px, xl: 1200px))
|
2014-12-20 15:03:30 +00:00
|
|
|
// md
|
2017-01-07 15:26:21 +00:00
|
|
|
// >> breakpoint-next(sm, $breakpoint-names: (xs sm md lg xl))
|
2014-12-20 15:03:30 +00:00
|
|
|
// md
|
|
|
|
@function breakpoint-next($name, $breakpoints: $grid-breakpoints, $breakpoint-names: map-keys($breakpoints)) {
|
|
|
|
$n: index($breakpoint-names, $name);
|
2019-06-17 06:00:36 +00: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 15:03:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Minimum breakpoint width. Null for the smallest (first) breakpoint.
|
|
|
|
//
|
2017-01-07 15:26:21 +00:00
|
|
|
// >> breakpoint-min(sm, (xs: 0, sm: 576px, md: 768px, lg: 992px, xl: 1200px))
|
2016-12-05 00:46:07 +00:00
|
|
|
// 576px
|
2014-12-20 15:03:30 +00:00
|
|
|
@function breakpoint-min($name, $breakpoints: $grid-breakpoints) {
|
|
|
|
$min: map-get($breakpoints, $name);
|
|
|
|
@return if($min != 0, $min, null);
|
|
|
|
}
|
|
|
|
|
2020-04-18 11:02:26 +00: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 10:13:37 +00:00
|
|
|
// See https://www.w3.org/TR/mediaqueries-4/#mq-min-max
|
2018-01-03 07:42:03 +00: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 15:03:30 +00:00
|
|
|
//
|
2020-04-18 11:02:26 +00:00
|
|
|
// >> breakpoint-max(md, (xs: 0, sm: 576px, md: 768px, lg: 992px, xl: 1200px))
|
2018-01-03 07:42:03 +00:00
|
|
|
// 767.98px
|
2014-12-20 15:03:30 +00:00
|
|
|
@function breakpoint-max($name, $breakpoints: $grid-breakpoints) {
|
2020-04-18 11:02:26 +00:00
|
|
|
$max: map-get($breakpoints, $name);
|
|
|
|
@return if($max and $max > 0, $max - .02, null);
|
2014-12-20 15:03:30 +00:00
|
|
|
}
|
|
|
|
|
2018-07-10 00:59:22 +00:00
|
|
|
// Returns a blank string if smallest breakpoint, otherwise returns the name with a dash in front.
|
2016-11-28 21:23:59 +00:00
|
|
|
// Useful for making responsive utilities.
|
|
|
|
//
|
2017-01-07 15:26:21 +00:00
|
|
|
// >> breakpoint-infix(xs, (xs: 0, sm: 576px, md: 768px, lg: 992px, xl: 1200px))
|
2016-11-28 21:23:59 +00:00
|
|
|
// "" (Returns a blank string)
|
2017-01-07 15:26:21 +00:00
|
|
|
// >> breakpoint-infix(sm, (xs: 0, sm: 576px, md: 768px, lg: 992px, xl: 1200px))
|
2016-11-28 21:23:59 +00:00
|
|
|
// "-sm"
|
|
|
|
@function breakpoint-infix($name, $breakpoints: $grid-breakpoints) {
|
|
|
|
@return if(breakpoint-min($name, $breakpoints) == null, "", "-#{$name}");
|
|
|
|
}
|
|
|
|
|
2014-12-20 15:03:30 +00:00
|
|
|
// Media of at least the minimum breakpoint width. No query for the smallest breakpoint.
|
2014-12-29 21:37:20 +00:00
|
|
|
// Makes the @content apply to the given breakpoint and wider.
|
|
|
|
@mixin media-breakpoint-up($name, $breakpoints: $grid-breakpoints) {
|
2014-12-20 15:03:30 +00: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 21:37:20 +00:00
|
|
|
// Makes the @content apply to the given breakpoint and narrower.
|
|
|
|
@mixin media-breakpoint-down($name, $breakpoints: $grid-breakpoints) {
|
2014-12-20 15:03:30 +00:00
|
|
|
$max: breakpoint-max($name, $breakpoints);
|
|
|
|
@if $max {
|
|
|
|
@media (max-width: $max) {
|
|
|
|
@content;
|
|
|
|
}
|
|
|
|
} @else {
|
|
|
|
@content;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-25 19:53:14 +00: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-07 01:59:14 +00:00
|
|
|
$min: breakpoint-min($lower, $breakpoints);
|
2017-03-26 05:23:40 +00:00
|
|
|
$max: breakpoint-max($upper, $breakpoints);
|
|
|
|
|
2017-10-03 04:38:59 +00:00
|
|
|
@if $min != null and $max != null {
|
|
|
|
@media (min-width: $min) and (max-width: $max) {
|
|
|
|
@content;
|
|
|
|
}
|
|
|
|
} @else if $max == null {
|
2018-01-13 07:45:21 +00:00
|
|
|
@include media-breakpoint-up($lower, $breakpoints) {
|
2017-10-03 04:38:59 +00:00
|
|
|
@content;
|
|
|
|
}
|
|
|
|
} @else if $min == null {
|
2018-01-13 07:45:21 +00:00
|
|
|
@include media-breakpoint-down($upper, $breakpoints) {
|
2017-10-03 04:38:59 +00:00
|
|
|
@content;
|
|
|
|
}
|
2015-08-25 19:53:14 +00:00
|
|
|
}
|
2015-09-02 17:09:55 +00:00
|
|
|
}
|
2016-06-09 15:07:27 +00: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 14:37:01 +00:00
|
|
|
$min: breakpoint-min($name, $breakpoints);
|
|
|
|
$next: breakpoint-next($name, $breakpoints);
|
|
|
|
$max: breakpoint-max($next);
|
2017-03-26 05:23:40 +00:00
|
|
|
|
2017-05-04 08:54:59 +00:00
|
|
|
@if $min != null and $max != null {
|
|
|
|
@media (min-width: $min) and (max-width: $max) {
|
|
|
|
@content;
|
|
|
|
}
|
|
|
|
} @else if $max == null {
|
2018-01-13 07:45:21 +00:00
|
|
|
@include media-breakpoint-up($name, $breakpoints) {
|
2017-08-17 08:27:59 +00:00
|
|
|
@content;
|
|
|
|
}
|
2017-05-04 08:54:59 +00:00
|
|
|
} @else if $min == null {
|
2020-08-18 14:37:01 +00:00
|
|
|
@include media-breakpoint-down($next, $breakpoints) {
|
2017-08-17 08:27:59 +00:00
|
|
|
@content;
|
|
|
|
}
|
2016-06-09 15:07:27 +00:00
|
|
|
}
|
|
|
|
}
|