I have the following code in my project:
:root,
[data-theme=light] {
--main-color: red;
--action-color: var(--main-color);
}
[data-theme=dark] {
--main-color: blue;
}
.action-box {
padding: 10px;
background-color: var(--action-color);
}
<div class="content" data-theme="dark">
<div class="action-box"></div>
</div>
The .action-box
is red, even though I have data-theme="dark"
on the parent container. Why isn't the color blue? I'm clearly overriding it in my CSS - --action-color
references --main-color
and --main-color
is set to blue
. The box actually turns blue when I apply data-theme="dark"
to my <html>
element, so how exactly does the scoping work here? For example, in the code below, the box turns blue:
:root,
[data-theme=light] {
--main-color: red;
--action-color: var(--main-color);
}
[data-theme=dark] {
--main-color: blue;
}
.action-box {
padding: 10px;
background-color: var(--action-color);
}
<html data-theme="dark">
<body>
<div class="content">
<div class="action-box"></div>
</div>
</body>
</html>
So what would be the workaround here for local scoping?