I'm interested in experimenting with CSS variables in my Angular 11 component.
<div class="main-content">
<a>Test Link</a>
</div>
Here is my app.component.css
:
div.main-content{
--main-color: red
}
a{
color: var(--main-color);
}
However, when I attempted to use :root
in my CSS, the link turned black.
:root {
--main-color: red
}
a{
color: var(--main-color);
}
The :root selector refers to the document's root element.
I'm puzzled as to why it's not working in my case.
UPDATE: Interestingly, when I added :root
to the default styles.css
in my Angular project, everything worked as expected globally. What could be the issue with my app.component.css
?