demo · v138
Typed arithmetic in calc()
Dial the base and ratio. The bar heights are computed in CSS as calc(var(--base) * pow(var(--ratio), n)) — a length times a unit-less power result. Typed arithmetic is what lets the unit travel cleanly through the expression.
checking support…
40px
1.35
base = 40px · ratio = 1.35
heights computed: —
heights computed: —
the code
.stage { --base: 40px; --ratio: 1.35; }
.bar.b3 { height: calc(var(--base) * pow(var(--ratio), 1.5)); }
/* pow() returns a unit-less number; multiplying it by a length
yields a length. Before typed arithmetic, this combination was
either rejected or produced a wrong-typed result. */
see also
- CSS typed arithmetic — feature index
- ChromeStatus entry
- Spec