CSS calc(100% – 0) is invalid, but calc(100% - 0px) is valid
webplatform.news
webplatform.news
Given that unitless zero is automatically coerced to a length when used as a constant (e.g. padding: 0), it is certainly a bug that this automatic coercion does not also happen when it is used in an expression.
CSS is typed. Every other context requires units, and computed values always have a unit.
Thanks, my bad. I fixed the title.
Example is you can * no problem, its expecting only a number for the 'read_next' but with the `-' it's expecting a denomination, otherwise it needs to keep a 'state' as such when moving on from reading a `0`
Edit : as pointed out by zarzavat : it does seem to be a bug in the spec in this case.
Pretty much what we're saying. It also fails when typed directly, at least in Firefox (as unnecessary as that 0 is).
While that might be true for all the length units defined in CSS, it's not true in general. E.g. in temperature, 0F != 0C
"For lengths, you can't use 0 to mean 0px (or another length unit); instead, you must use the version with the unit: margin-top: calc(0px + 20px); is valid, while margin-top: calc(0 + 20px); is invalid."
https://developer.mozilla.org/en-US/docs/Web/CSS/calc?retire...
Sadly here it does force a special case where it either becomes a nop or it adopts the units required. Not sure which is best.
Note your preprocessor may be overly ambitious with stripping units, which I think is frankly a dumb linter rule always, but that’s not the browser’s fault.
IMHO the issue is that an exception for zero exists at all. Units should be required in all places.
> Because <number-token>s are always interpreted as <number>s or <integer>s, "unitless 0" <length>s aren’t supported in math functions. That is, width: calc(0 + 5px); is invalid, because it’s trying to add a <number> to a <length>, even though both width: 0; and width: 5px; are valid.
— https://www.w3.org/TR/css-values-4/#calc-type-checking
(This also appears in the latest Editor’s Draft.)