1 // Breakpoint viewport sizes and media queries.
3 // Breakpoints are defined as a map of (name: minimum width), order from small to large:
5 // (xs: 0, sm: 576px, md: 768px, lg: 992px, xl: 1200px)
7 // The map defined in the `$grid-breakpoints` global variable is used as the `$breakpoints` argument by default.
9 // Name of the next breakpoint, or null for the last breakpoint.
11 // >> breakpoint-next(sm)
13 // >> breakpoint-next(sm, (xs: 0, sm: 576px, md: 768px, lg: 992px, xl: 1200px))
15 // >> breakpoint-next(sm, $breakpoint-names: (xs sm md lg xl))
17 @function breakpoint-next($name, $breakpoints: $grid-breakpoints, $breakpoint-names: map-keys($breakpoints)) {
18 $n: index($breakpoint-names, $name);
19 @return if($n < length($breakpoint-names), nth($breakpoint-names, $n + 1), null);
22 // Minimum breakpoint width. Null for the smallest (first) breakpoint.
24 // >> breakpoint-min(sm, (xs: 0, sm: 576px, md: 768px, lg: 992px, xl: 1200px))
26 @function breakpoint-min($name, $breakpoints: $grid-breakpoints) {
27 $min: map-get($breakpoints, $name);
28 @return if($min != 0, $min, null);
31 // Maximum breakpoint width. Null for the largest (last) breakpoint.
32 // The maximum value is calculated as the minimum of the next one less 0.02px
33 // to work around the limitations of `min-` and `max-` prefixes and viewports with fractional widths.
34 // See https://www.w3.org/TR/mediaqueries-4/#mq-min-max
35 // Uses 0.02px rather than 0.01px to work around a current rounding bug in Safari.
36 // See https://bugs.webkit.org/show_bug.cgi?id=178261
38 // >> breakpoint-max(sm, (xs: 0, sm: 576px, md: 768px, lg: 992px, xl: 1200px))
40 @function breakpoint-max($name, $breakpoints: $grid-breakpoints) {
41 $next: breakpoint-next($name, $breakpoints);
42 @return if($next, breakpoint-min($next, $breakpoints) - .02px, null);
45 // Returns a blank string if smallest breakpoint, otherwise returns the name with a dash in front.
46 // Useful for making responsive utilities.
48 // >> breakpoint-infix(xs, (xs: 0, sm: 576px, md: 768px, lg: 992px, xl: 1200px))
49 // "" (Returns a blank string)
50 // >> breakpoint-infix(sm, (xs: 0, sm: 576px, md: 768px, lg: 992px, xl: 1200px))
52 @function breakpoint-infix($name, $breakpoints: $grid-breakpoints) {
53 @return if(breakpoint-min($name, $breakpoints) == null, "", "-#{$name}");
56 // Media of at least the minimum breakpoint width. No query for the smallest breakpoint.
57 // Makes the @content apply to the given breakpoint and wider.
58 @mixin media-breakpoint-up($name, $breakpoints: $grid-breakpoints) {
59 $min: breakpoint-min($name, $breakpoints);
61 @media (min-width: $min) {
69 // Media of at most the maximum breakpoint width. No query for the largest breakpoint.
70 // Makes the @content apply to the given breakpoint and narrower.
71 @mixin media-breakpoint-down($name, $breakpoints: $grid-breakpoints) {
72 $max: breakpoint-max($name, $breakpoints);
74 @media (max-width: $max) {
82 // Media that spans multiple breakpoint widths.
83 // Makes the @content apply between the min and max breakpoints
84 @mixin media-breakpoint-between($lower, $upper, $breakpoints: $grid-breakpoints) {
85 $min: breakpoint-min($lower, $breakpoints);
86 $max: breakpoint-max($upper, $breakpoints);
88 @if $min != null and $max != null {
89 @media (min-width: $min) and (max-width: $max) {
92 } @else if $max == null {
93 @include media-breakpoint-up($lower, $breakpoints) {
96 } @else if $min == null {
97 @include media-breakpoint-down($upper, $breakpoints) {
103 // Media between the breakpoint's minimum and maximum widths.
104 // No minimum for the smallest breakpoint, and no maximum for the largest one.
105 // Makes the @content apply only to the given breakpoint, not viewports any wider or narrower.
106 @mixin media-breakpoint-only($name, $breakpoints: $grid-breakpoints) {
107 $min: breakpoint-min($name, $breakpoints);
108 $max: breakpoint-max($name, $breakpoints);
110 @if $min != null and $max != null {
111 @media (min-width: $min) and (max-width: $max) {
114 } @else if $max == null {
115 @include media-breakpoint-up($name, $breakpoints) {
118 } @else if $min == null {
119 @include media-breakpoint-down($name, $breakpoints) {