Last active
December 20, 2021 14:12
-
-
Save DracoBlue/8440904 to your computer and use it in GitHub Desktop.
respond-to with multiple breakpoints and nice way to define them (in scss)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@mixin respond-to($medias...) { | |
$breakpoints-length: length($respond-to-breakpoints); | |
@each $media in $medias { | |
$had-a-hit: false; | |
@for $i from 1 through $breakpoints-length { | |
$breakpoint: nth($respond-to-breakpoints, $i); | |
@if $media == nth($breakpoint, 1) { | |
$definition: nth($breakpoint, 2); | |
$had-a-hit: true; | |
@media #{$definition} { | |
@content; | |
} | |
} | |
} | |
@if $media == $respond-to-no-mediaqueries-fallback { | |
.#{$respond-to-fallback-class} & { | |
@content; | |
} | |
} | |
@if $had-a-hit == false { | |
@warn "Media #{media} not found!"; | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$respond-to-no-mediaqueries-fallback: desktop; | |
$respond-to-fallback-class: lt-ie9; | |
$respond-to-breakpoints: ( | |
desktop "(min-width: 721px)", | |
pad "(min-width: 321px) and (max-width: 720px)", | |
mobile "(max-width: 320px)" | |
); | |
@import "_respond-to"; | |
.my-class { | |
@include respond-to(desktop, pad) { | |
color: #ff0; | |
} | |
@include respond-to(mobile) { | |
color: #f0f; | |
} | |
font-size: 12px; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
you need to delete the last comma after – mobile "(max-width: 320px)", – or you get an error