I am working with angular 12 and I am creating dynamic theme change.
When my application is loaded according to the selected theme I set all my color variables like this:
document.documentElement.style.setProperty(colorKey, colorValue);
After it, all colors are set to the document element not to the root element.
As you see I also have some variables to the root element. But those variables are defined in the css file as:
:root {
--primary: #005d7a;
--primary-50: #edf1f2;
--primary-400: #0094bd;
--primary-700: #027498;
--secondary-50: #ffebb7;
--silver: #3a3a3a;
--silver-light: #e4e7ea;
--silver-light-border: #dad7d6;
--main-background: white;
--main-page-background: #e4e7ea;
--main-text-color: #3a3a3a;
--disabled-color: #ccc;
}
And that works fine.
My question is:
- How to set other variables which are defined from the ts file to the root not to the document element ?
- According to the post root selector is stronger than document. How then (as you can see on the image above) my root primary-50 color is overridden with document primary-50 ?