-
More cascading "gotcha's" with CSS variables: html { color: var(--text-color, red); } p { --text-color: blue; } p color is still red, because we inherit the *computed* value
red
from html, not the specified valuevar(--text-color, red)
. -
Changing the variable does not cause the inherited value to re-calculate. We can do that by using e.g.: * { color: var(--text-color); } /* re-calculate everywhere */ html { --text-color: red; } p { --text-color: blue; }
-
Doesn’t need to be the universal selector, as long as it matches the places you need to re-calc. Which also doesn’t have to be the same place you define the variable… But the re-calc location has to have access to the updated variable - directly or by inheriting.