Feature: support var(--variables) with fallback for runtime change
See original GitHub issueWe have in :root a map of variables with can be use by default in all elements/components with proper fallback. Can we add another $support-css4 to generate additional fallback styles? This feature can be added later in roadmap if docs aren’t stable right now.
Example:
.swatch-blue {
color: #fff;
background-color: #007bff;
}
to:
.swatch-blue {
color: #fff;
background-color: #007bff;
background-color: var(--blue);
}
Benefits:
- works same as before
- new way to change color in runtime!
- can be change by js in one place to enable fast change of parameters
- can be enabled by setting
$support-runtime-variable or $support-css4
(or something like that)
- this feature expand to not only colors but breakpoints and other properties
Need to:
- check if some browser incorrect implement that feature
- invert colors can be tricky
How to do that in clever way and I added benefit of this approach: https://codepen.io/anon/pen/XVLvLQ
Better idea:
- create some tool like autoprefixer to enable it by default without bloat code. But add documentation about that solution on site so no new issue will be generated.
Documentation and credits for amazing work: https://getbootstrap.com/docs/4.0/getting-started/theming/#color https://css-tricks.com/difference-between-types-of-css-variables/
Issue Analytics
- State:
- Created 6 years ago
- Reactions:5
- Comments:12 (2 by maintainers)
Top Results From Across the Web
CSS — ::selection with var() fallback - Stack Overflow
I'm curious of your use case where an unset variable could find it's way into your code that's not because of a typo....
Read more >Using CSS custom properties (variables) - MDN Web Docs
Custom property fallback values. Using the var() function, you can define multiple fallback values when the given variable is not yet defined; ...
Read more >How to use CSS custom properties (a.k.a. variables)
It is important to note the var() function provides a fallback mechanism itself, in case your custom property is not set. The function...
Read more >A user's guide to CSS variables – Increment: Frontend
Their values are referenced via the function var(--name) , which can be used in any CSS property. The var() function also supports a...
Read more >A Complete Guide To CSS Variables [With Examples]
The fallback value works as a safety net in the variable ... This makes the variable static and irresistible to change at runtime....
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 Free
Top 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
Being able to easily change the theme colors at runtime would be a very neat feature.
Let me know if I can help write a PR to add support.
Closing out as not a bug and not a feature request we can take on right now. I think we’re better served in v4’s lifespan by focusing first on Sass variables and then CSS as a first class come v5 or so.