I'm using Next.js 9.53
I use the basic CSS module support that comes with Next.js - no CSS pre-processor (less
, sass
, etc.) and no CSS-in-JS (styled-components
etc.)
At the moment, I write my CSS mobile-first and then have a bunch of redundant media queries looking like:
/* "desktop" */
@media screen and (min-width: 1024px) {
...
}
I have redundant copies of that media query in a few different modules. I like having the alternative styles close to the CSS that defines the default styling. But I don't like the "magic number" aspect of that query.
I do also have a set of "global" CSS, where I define a few high-level things and also some CSS variables that I then re-use throughout all the module CSS to avoid spreading around magic numbers (colors, mostly). But CSS variables don't work for media queries, as explained in this SO answer.
Is there some way similar to CSS variables that I can share my size breakpoints across a bunch of different media queries?
- I want to keep my alternative CSS queries near their default counterparts (i.e. I don't want to centralise the alternative CSS from all the different modules into one place).
- I'd prefer a simple solution to this if possible - I'd rather not make large changes to my build process just for this (like introducing a CSS pre-processor).