Skip to content

Instantly share code, notes, and snippets.

@rn4n
Last active April 12, 2021 04:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rn4n/a9e6e9b85b5e4b5e7b2b5abc97718e8a to your computer and use it in GitHub Desktop.
Save rn4n/a9e6e9b85b5e4b5e7b2b5abc97718e8a to your computer and use it in GitHub Desktop.
Media queries mixin for Stylus
/**
* 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}
// 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