Variable Cascading
suggest changeCSS variables cascade in much the same way as other properties, and can be restated safely.
You can define a variable more than once. The winning declaration follows the cascade: when specificity is equal, the later one applies.
Assuming this HTML:
<a class="button">Button Green</a>
<a class="button button_red">Button Red</a>
<a class="button">Button Hovered On</a>
We can write this CSS:
.button {
--color: green;
padding: .5rem;
border: 1px solid var(--color);
color: var(--color);
}
.button:hover {
--color: blue;
}
.button_red {
--color: red;
}
And get this result:
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents