Skip to content

Instantly share code, notes, and snippets.

@jwchristiansen
Last active Sep 8, 2020
Embed
What would you like to do?
$breakpoints: (
screen: 640px
);
@mixin respond-above($breakpoint) {
@if map-has-key($breakpoints, $breakpoint) {
$breakpoint-value: map-get($breakpoints, $breakpoint);
@media (min-width: $breakpoint-value) {
@content;
}
} @else {
@warn 'Invalid breakpoint: #{$breakpoint}.';
}
}
@mixin respond-below($breakpoint) {
@if map-has-key($breakpoints, $breakpoint) {
$breakpoint-value: map-get($breakpoints, $breakpoint);
@media (max-width: ($breakpoint-value - 1)) {
@content;
}
} @else {
@warn 'Invalid breakpoint: #{$breakpoint}.';
}
}
@mixin respond-between($lower, $upper) {
@if map-has-key($breakpoints, $lower) and map-has-key($breakpoints, $upper) {
$lower-breakpoint: map-get($breakpoints, $lower);
$upper-breakpoint: map-get($breakpoints, $upper);
@media (min-width: $lower-breakpoint) and (max-width: ($upper-breakpoint - 1)) {
@content;
}
} @else {
@if (map-has-key($breakpoints, $lower) == false) {
@warn 'Your lower breakpoint was invalid: #{$lower}.';
}
@if (map-has-key($breakpoints, $upper) == false) {
@warn 'Your upper breakpoint was invalid: #{$upper}.';
}
}
}
// thanks to Glenn McComb for these breakpoints SCSS mixins
// https://glennmccomb.com/articles/useful-sass-scss-media-query-mixins-for-bootstrap/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment