2014-12-20 16:03:30 +01: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 16:26:21 +01:00
|
|
|
// (xs: 0, sm: 576px, md: 768px, lg: 992px, xl: 1200px)
|
2014-12-20 16:03:30 +01: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 16:26:21 +01:00
|
|
|
// >> breakpoint-next(sm, (xs: 0, sm: 576px, md: 768px, lg: 992px, xl: 1200px))
|
2014-12-20 16:03:30 +01:00
|
|
|
// md
|
2017-01-07 16:26:21 +01:00
|
|
|
// >> breakpoint-next(sm, $breakpoint-names: (xs sm md lg xl))
|
2014-12-20 16:03:30 +01:00
|
|
|
// md
|
|
|
|
@function breakpoint-next($name, $breakpoints: $grid-breakpoints, $breakpoint-names: map-keys($breakpoints)) {
|
|
|
|
$n: index($breakpoint-names, $name);
|
2017-01-14 06:33:21 +01:00
|
|
|
@return if($n < length($breakpoint-names), nth($breakpoint-names, $n + 1), null);
|
2014-12-20 16:03:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Minimum breakpoint width. Null for the smallest (first) breakpoint.
|
|
|
|
//
|
2017-01-07 16:26:21 +01:00
|
|
|
// >> breakpoint-min(sm, (xs: 0, sm: 576px, md: 768px, lg: 992px, xl: 1200px))
|
2016-12-05 01:46:07 +01:00
|
|
|
// 576px
|
2014-12-20 16:03:30 +01:00
|
|
|
@function breakpoint-min($name, $breakpoints: $grid-breakpoints) {
|
|
|
|
$min: map-get($breakpoints, $name);
|
|
|
|
@return if($min != 0, $min, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Maximum breakpoint width. Null for the largest (last) breakpoint.
|
|
|
|
// The maximum value is calculated as the minimum of the next one less 0.1.
|
|
|
|
//
|
2017-01-07 16:26:21 +01:00
|
|
|
// >> breakpoint-max(sm, (xs: 0, sm: 576px, md: 768px, lg: 992px, xl: 1200px))
|
2015-08-31 02:23:43 +02:00
|
|
|
// 767px
|
2014-12-20 16:03:30 +01:00
|
|
|
@function breakpoint-max($name, $breakpoints: $grid-breakpoints) {
|
|
|
|
$next: breakpoint-next($name, $breakpoints);
|
2015-08-31 02:23:43 +02:00
|
|
|
@return if($next, breakpoint-min($next, $breakpoints) - 1px, null);
|
2014-12-20 16:03:30 +01:00
|
|
|
}
|
|
|
|
|
2016-11-28 22:23:59 +01:00
|
|
|
// Returns a blank string if smallest breakpoint, otherwise returns the name with a dash infront.
|
|
|
|
// Useful for making responsive utilities.
|
|
|
|
//
|
2017-01-07 16:26:21 +01:00
|
|
|
// >> breakpoint-infix(xs, (xs: 0, sm: 576px, md: 768px, lg: 992px, xl: 1200px))
|
2016-11-28 22:23:59 +01:00
|
|
|
// "" (Returns a blank string)
|
2017-01-07 16:26:21 +01:00
|
|
|
// >> breakpoint-infix(sm, (xs: 0, sm: 576px, md: 768px, lg: 992px, xl: 1200px))
|
2016-11-28 22:23:59 +01:00
|
|
|
// "-sm"
|
|
|
|
@function breakpoint-infix($name, $breakpoints: $grid-breakpoints) {
|
|
|
|
@return if(breakpoint-min($name, $breakpoints) == null, "", "-#{$name}");
|
|
|
|
}
|
|
|
|
|
2014-12-20 16:03:30 +01:00
|
|
|
// Media of at least the minimum breakpoint width. No query for the smallest breakpoint.
|
2014-12-29 22:37:20 +01:00
|
|
|
// Makes the @content apply to the given breakpoint and wider.
|
|
|
|
@mixin media-breakpoint-up($name, $breakpoints: $grid-breakpoints) {
|
2014-12-20 16:03:30 +01: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 22:37:20 +01:00
|
|
|
// Makes the @content apply to the given breakpoint and narrower.
|
|
|
|
@mixin media-breakpoint-down($name, $breakpoints: $grid-breakpoints) {
|
2014-12-20 16:03:30 +01:00
|
|
|
$max: breakpoint-max($name, $breakpoints);
|
|
|
|
@if $max {
|
|
|
|
@media (max-width: $max) {
|
|
|
|
@content;
|
|
|
|
}
|
|
|
|
} @else {
|
|
|
|
@content;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-25 21:53:14 +02: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 03:59:14 +02:00
|
|
|
$min: breakpoint-min($lower, $breakpoints);
|
2017-03-26 07:23:40 +02:00
|
|
|
$max: breakpoint-max($upper, $breakpoints);
|
|
|
|
|
2017-10-03 06:38:59 +02:00
|
|
|
@if $min != null and $max != null {
|
|
|
|
@media (min-width: $min) and (max-width: $max) {
|
|
|
|
@content;
|
|
|
|
}
|
|
|
|
} @else if $max == null {
|
|
|
|
@include media-breakpoint-up($lower) {
|
|
|
|
@content;
|
|
|
|
}
|
|
|
|
} @else if $min == null {
|
|
|
|
@include media-breakpoint-down($upper) {
|
|
|
|
@content;
|
|
|
|
}
|
2015-08-25 21:53:14 +02:00
|
|
|
}
|
2015-09-02 19:09:55 +02:00
|
|
|
}
|
2016-06-09 17:07:27 +02: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) {
|
2017-03-26 07:23:40 +02:00
|
|
|
$min: breakpoint-min($name, $breakpoints);
|
|
|
|
$max: breakpoint-max($name, $breakpoints);
|
|
|
|
|
2017-05-04 10:54:59 +02:00
|
|
|
@if $min != null and $max != null {
|
|
|
|
@media (min-width: $min) and (max-width: $max) {
|
|
|
|
@content;
|
|
|
|
}
|
|
|
|
} @else if $max == null {
|
2017-08-17 10:27:59 +02:00
|
|
|
@include media-breakpoint-up($name) {
|
|
|
|
@content;
|
|
|
|
}
|
2017-05-04 10:54:59 +02:00
|
|
|
} @else if $min == null {
|
2017-08-17 10:27:59 +02:00
|
|
|
@include media-breakpoint-down($name) {
|
|
|
|
@content;
|
|
|
|
}
|
2016-06-09 17:07:27 +02:00
|
|
|
}
|
|
|
|
}
|