Solving SASS’s media query duplication problem (medium.com)
7 years ago from Dom Briggs, Design Lead - capsulecrm.com
7 years ago from Dom Briggs, Design Lead - capsulecrm.com
This seems like quite a lot of extra work to solve a problem that doesn't really exist tbh. Being able to just put a media query inside a selector is one of the convenient things about Sass and this breaks that.
True my preferred solution would be to keep things nested but I didn't like the duplication. You can argue it doesn't really matter for most devices for performance or file size but if I can save a few kb's I'm happy to.
Although I found being able to jump into a component file scroll to the bottom and know exactly which classes were responsive speeded up my workflow when making changes.
This is a clever solution, but it seems like it would make maintainability a bit of a chore (now I have my styles in two locations, even if one is just a call).
Of course, there is a post-processor option, such as gulp-merge-media-queries
. It's not the most optimal solution. What would be cool is an engine that recursively goes through every @media
call before generating markup. It would probably be slow as hell, but then you could (ideally) update variable values based on @media
rules.
Awesome thanks, I did not know about this! I'll include in an edit in the post :) Thanks!
I just added an update describing the benefits of the approach on workflow. I realised this was actually the real benefit for my team using this approach not just the removal of duplicated media queries. https://medium.com/@hallodom/the-solution-to-media-queries-in-sass-5493ebe16844#.5wquz66sn
Thanks for reading!
Designer News
Where the design community meets.
Designer News is a large, global community of people working or interested in design and technology.
Have feedback?
Login to Comment
You'll need to log in before you can leave a comment.
LoginRegister Today
New accounts can leave comments immediately, and gain full permissions after one week.
Register now