As can be seen in the pen below, css variables which use calc don't seem to respect the cascade nature of the variables:
:root {
--font-size-mult: 1;
--font-size: calc(var(--font-size-mult) * 16px);
}
* {
font-size: var(--font-size);
}
.large {
--font-size-mult: 2;
}
The expected behaviour is that any part of the document which has the .large class would have a font-size twice as big as the regular 16px. What can be seen in the example is that if I redefine the font-size variable inside of .large, I get the desired behaviour, but this seems counter-intuitive since the value of --font-size is already what it needs to be to resolve to the correct value.
This seems to be the case in all browsers I have tested, so it is probably part of the spec, but it doesn't seem to fit very well with how CSS works. I would think variable values would be calculated based on the values of other variables in the current element's scope, rather than the scope of where the variable was defined.
https://codepen.io/Smilebags/pen/MrRKMY
Is this expected behaviour? Should this be the case?