Re: [csswg-drafts] [css-values] max() issue (#11768)

This is actually failing before the "consistent type" is even checked. See <https://drafts.csswg.org/css-values-4/#determine-the-type-of-a-calculation> - the unknown unit has a type of "failure", and this percolates up thru the entire expression, causing it to fail to match any of the types like `<length>`, etc. So this is actually failing *at parse time*, and causing the declaration to be thrown out.

This is identical to the behavior if you use the unknown unit *outside* of a math expression: `block-size: 100lvh;` will also be invalid. We don't really want to automatically mask bugs like this.

There are several ways to deal with this today - an `@supports` rule testing the use of a unit, or a registered custom property with the desired type and an initial value (the unknown unit will cause it to fail to parse, so it'll become the initial value instead). Once [variable units](https://drafts.csswg.org/css-variables-2/#variable-units) are supported, you can handle this sort of thing very gracefully inline, like:

```css
@property --lvh {
  syntax: "<length>";
  initial: 1vh; /* a dependable fallback */
  inherits: true;
}
:root {
  --lvh: 1lvh; /* the actual value you want to use */
}

...elsewhere...
  block-size: max(3rem, calc((100--lvh - 3.75rem - 4.75rem) / 24));
```

-- 
GitHub Notification of comment by tabatkins
Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/11768#issuecomment-2679625499 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Monday, 24 February 2025 20:55:28 UTC