Last active
April 12, 2021 04:06
-
-
Save rn4n/a9e6e9b85b5e4b5e7b2b5abc97718e8a to your computer and use it in GitHub Desktop.
Media queries mixin for Stylus
This file contains 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
/** | |
* Thanks to Martin Laine | |
* http://1pixelout.net/2015/10/02/simple-breakpoint-media-queries-with-stylus/ | |
**/ | |
media_queries = { | |
mobile : "only screen and (max-width: 600px)", | |
tablet : "only screen and (min-width: 601px) and (max-width: 800px)", | |
desktop : "only screen and (min-width: 801px)" | |
} | |
for_breakpoint(breakpoints) | |
conditions = () | |
for breakpoint in breakpoints | |
push(conditions, media_queries[breakpoint]) | |
conditions = join(", ", conditions) | |
@media conditions | |
{block} |
This file contains 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
// Usage: | |
.sidebar | |
width 200px | |
+for_breakpoint(mobile tablet) | |
display none | |
// Compiles to: | |
.sidebar { | |
width: 200px; | |
} | |
@media only screen and (max-width: 600px), only screen and (min-width: 601px) and (max-width: 800px) { | |
.sidebar { | |
display: none; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment