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.01px
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
36 // >> breakpoint-max(sm, (xs: 0, sm: 576px, md: 768px, lg: 992px, xl: 1200px))
38 @function breakpoint-max($name, $breakpoints: $grid-breakpoints) {
39 $next: breakpoint-next($name, $breakpoints);
40 @return if($next, breakpoint-min($next, $breakpoints) - .01px, null);
43 // Returns a blank string if smallest breakpoint, otherwise returns the name with a dash infront.
44 // Useful for making responsive utilities.
46 // >> breakpoint-infix(xs, (xs: 0, sm: 576px, md: 768px, lg: 992px, xl: 1200px))
47 // "" (Returns a blank string)
48 // >> breakpoint-infix(sm, (xs: 0, sm: 576px, md: 768px, lg: 992px, xl: 1200px))
50 @function breakpoint-infix($name, $breakpoints: $grid-breakpoints) {
51 @return if(breakpoint-min($name, $breakpoints) == null, "", "-#{$name}");
54 // Media of at least the minimum breakpoint width. No query for the smallest breakpoint.
55 // Makes the @content apply to the given breakpoint and wider.
56 @mixin media-breakpoint-up($name, $breakpoints: $grid-breakpoints) {
57 $min: breakpoint-min($name, $breakpoints);
59 @media (min-width: $min) {
67 // Media of at most the maximum breakpoint width. No query for the largest breakpoint.
68 // Makes the @content apply to the given breakpoint and narrower.
69 @mixin media-breakpoint-down($name, $breakpoints: $grid-breakpoints) {
70 $max: breakpoint-max($name, $breakpoints);
72 @media (max-width: $max) {
80 // Media that spans multiple breakpoint widths.
81 // Makes the @content apply between the min and max breakpoints
82 @mixin media-breakpoint-between($lower, $upper, $breakpoints: $grid-breakpoints) {
83 $min: breakpoint-min($lower, $breakpoints);
84 $max: breakpoint-max($upper, $breakpoints);
86 @if $min != null and $max != null {
87 @media (min-width: $min) and (max-width: $max) {
90 } @else if $max == null {
91 @include media-breakpoint-up($lower) {
94 } @else if $min == null {
95 @include media-breakpoint-down($upper) {
101 // Media between the breakpoint's minimum and maximum widths.
102 // No minimum for the smallest breakpoint, and no maximum for the largest one.
103 // Makes the @content apply only to the given breakpoint, not viewports any wider or narrower.
104 @mixin media-breakpoint-only($name, $breakpoints: $grid-breakpoints) {
105 $min: breakpoint-min($name, $breakpoints);
106 $max: breakpoint-max($name, $breakpoints);
108 @if $min != null and $max != null {
109 @media (min-width: $min) and (max-width: $max) {
112 } @else if $max == null {
113 @include media-breakpoint-up($name) {
116 } @else if $min == null {
117 @include media-breakpoint-down($name) {