Can't use CSS variables or SCSS variables based on CSS variables in module configurations
See original GitHub issueIf one would like to use dynamic variables the best practice is to have them as CSS variables and then use them as values for SCSS variables, the following example works fine. If the --primary variables is manipulated by JavaScript the header’s background color changes.
:root {
--primary: red;
}
$primary: var(--primary);
header {
background-color: $primary;
}
Although if one thinks in modular it’s better to multiple files and module configurations but it just doesn’t work the way it should. If this is get compiled, fails immediately even if using SCSS variables is skipped and only CSS variables are used:
Colors partial
$primary: var(--primary);
Header partial
$header-bg: grey !default;
header {
background-color: $header-bg;
}
Body style
@use 'colors' as colors;
@use 'header' as header with {
$header-bg: colors.$primary;
}
Main style
:root {
--primary: red;
}
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Can't use a css variable from scss file in node_modules
CSS variables are dynamic at run time and can't be transformed by SASS at compile time. The SASS compiler is picking it up...
Read more >Variables - Sass
CSS variables can have different values for different elements, but Sass variables only have one value at a time. Sass variables are imperative,...
Read more >Using CSS custom properties (variables) - MDN Web Docs
Custom properties (sometimes referred to as CSS variables or cascading variables) are entities defined by CSS authors that contain specific ...
Read more >How do I use css variables with css modules in Next.JS #12147
1.Go to the styles folder and create a file roots.css · 2. Put all your css variables. · 3. Go to pages/_app.js and...
Read more >Getting JavaScript to Talk to CSS and Sass
We can also retrieve CSS variables using getComputedStyle in JavaScript. ... that are capable of importing and translating Sass modules.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Well, Sass color functions expect to get colors to be able to change them.
var(--primary)
is not a Sass color. It is an unquoted string. So it cannot be changed bycolor.change
. that’s totally expected.Oh, thank you for the info, I didn’t know this. I use a UI framework based on the pattern above and wanted to implement dynamic color theme change in runtime.