Last active
December 18, 2015 19:29
-
-
Save jpavon/5833682 to your computer and use it in GitHub Desktop.
Element query workaround
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 elementquery() { | |
@media (min-width: 32.5em) { .content & { @content; } } | |
@media (min-width: 90em) { .aside & { @content; } } | |
} | |
.schedule-component { | |
@include elementquery() { | |
color: pink; | |
} | |
} | |
// Output: | |
@media (min-width: 32.5em) { | |
.content .schedule-component { | |
color: pink; | |
} | |
} | |
@media (min-width: 90em) { | |
.aside .schedule-component { | |
color: pink; | |
} | |
} |
Why would the aside .schedule-component need to be in it's own media query? At lower than 90em does it need to be the full version of the schedule?
Now I see what you mean by passing multiple values through. Check out https://gist.github.com/micahgodbolt/5851228
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This looks nice, but is there a way to pass pairs of parent selectors and media queries as arguments into the
elementquery
mixin instead of looking for that&
parent?Our problem is that we have many blocks of selectors and styles that must apply at a given breakpoint, rather than just minor style adjustments to one element.
So, it's less like..
.schedule-component { color: pink; }
, and more like...Our article example was admittedly simplistic. In reality, this is the sort of output we'd need to achieve:
This is why we were hoping something like this was possible, as it'd be pretty concise and allow us to write the styles one time, inline in the same file.
The syntax of how the parent selector and breakpoints are passed-in is less important than the ability to include a large block of styles and have them included within separate media queries with all selectors prefixed.
Any thoughts on that feasibility?