Skip to content

Instantly share code, notes, and snippets.

@TheDutchCoder
Last active August 29, 2015 14:11
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 TheDutchCoder/251ef445a85899ca96dc to your computer and use it in GitHub Desktop.
Save TheDutchCoder/251ef445a85899ca96dc to your computer and use it in GitHub Desktop.
// Very basic media query mixin with the option to disable the entire
// media query, which will result in compounded styles for IE8.
//
// The cascade will let you end up with the "biggest" styles. This is
// far from perfect (e.g. if you have queries for much larger/wider
// media, IE8 will end up using that).
@mixin mq($media) {
@if $no-mq == true { @content; }
@else {
@if $media == "lap" { @media only screen and (min-width: 40em) { @content; } }
@if $media == "desk" { @media only screen and (min-width: 60em) { @content; } }
}
}
// Example SASS.
html {
color: #222;
@include mq(desk) {
color: red;
}
}
// Output with `$no-mq: false;`.
// Great, normal media query, all semi-decent browsers are happy.
html {
color: #222;
}
@media screen and (min-width: 60em) {
html {
color: red;
}
}
// Output with `$no-mq: true;`.
// Ugly but it works, only one CSS file needed for sub-par browsers!
html {
color: #222;
color: red;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment