Last active
August 29, 2015 14:02
-
-
Save benshimmin/296fb1086472fd7569d1 to your computer and use it in GitHub Desktop.
Sass 3.2+, media queries, and @content
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
// We had a use-case where we wanted to apply some styles at a certain | |
// breakpoint *and* to any IEs less than 9 (using the standard .lt-ie9 | |
// class). | |
// | |
// The developer tasked with this decided Sass couldn't do it, | |
// wrote a snarky comment, and then copied and pasted the code twice, | |
// sort of like this: | |
@media only screen and (max-width: 500px) { | |
a { ... } | |
b { ... } | |
c { ... } | |
} | |
.lt-ie9 { | |
a { ... } | |
b { ... } | |
c { ... } | |
} | |
// You don't need to do that. You can instead use @content like this: | |
@mixin my-content-mixin { | |
@media only screen and (max-width: 500px) { | |
@content; | |
} | |
.lt-ie9 { | |
@content; | |
} | |
} | |
@include my-content-mixin { | |
a { ... } | |
b { ... } | |
c { ... } | |
} | |
// The output is identical in both cases. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment