Media Queries in SCSS24 Jul 2015 | Ben Robertson
We write all our media queries within the _states.scss file. If the project you are working on follows our standard for SMACSS organization, you should be able to find that file inside:
Instead of doing just a few big media query wrappers (one for mobile, one for tablet, etc), we nest our media queries inside of the module–or element–that they affect. This makes our code easy to read and it makes it a lot easier to maintain, since we know that all media queries are right with the element they affect.
We also use a really nifty mixin that makes our media queries super clean. Be sure to include this in
When you want to use the mixin to add a media query, you do it like so:
Here’s your css output:
What about performance?
Some people say this code is too bloated. Here’s some awesome research that Kimberly Blessing did on optimizing media queries, basically showing that it’s not a big deal.
Chris Coyier and Dave Rupert also addressed the issue on shoptalkshow.