Skip to content

Instantly share code, notes, and snippets.

@b44rd
Last active December 30, 2015 11:29
Show Gist options
  • Save b44rd/7822440 to your computer and use it in GitHub Desktop.
Save b44rd/7822440 to your computer and use it in GitHub Desktop.
A responsive elementquery mixin for scss. Uses http://marcj.github.io/css-element-queries/
// The mixin
@mixin elementquery ($elementsize) {
@if $elementsize == small {
&[max-width="200px"]{ @content; }
}
@else if $elementsize == medium {
&[max-width="500px"]{ @content; }
}
@else if $elementsize == large {
&[max-width="800px"]{ @content; }
}
@else if $elementsize == full {
&[max-width="1200px"]{ @content; }
}
@else {
&[max-width="#{$elementsize}"]{ @content; }
}
}
// Usage
.test {
background: #ff0;
@include elementquery(340px){
background: #fc6;
};
@include elementquery(large){
background: #f00;
};
}
// Compiled result
.test { background: #ff0; }
.test[max-width="340px"] { background: #fc6; }
.test[max-width="800px"] { background: #f00; }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment