Open benface opened 9 months ago
I think it's strange to only have this for em
and not other font-relative units. Could even make sense for container-query units.
And rather than adding a preserved variant of each unit, maybe we should consider a more general solution? #2749 is basically the same problem but with variables.
Yeah, this is a general issue where people want "late resolution" of something, so it inherits as-is and gets resolved immediately after.
If we want it for things other than variables, that'll point to a slightly different syntax than a variable-focused one.
Awesome. I agree that a more general solution would be better. Should I close this issue and post about my line-height
use case in #2749 instead?
This was discussed previously in #2165 (and I'm sure in other places as well), but a different solution was agreed upon for that specific issue. However, I think there's still a need for a font-size-relative unit that inherits like percentages do, meaning that it gets preserved rather than resolved to an absolute value before being inherited. I am proposing
upm
(units per em) simply because it was mentioned by @fantasai here, but it could be anything. In some cases, percentages work exactly like that (e.g. inletter-spacing
, as agreed upon in the aforementioned issue), but the issue with percentages is that they refer to different things depending on the property. There is a need for a unit that is always relative to the current, actual font-size being used on the element the value is applied to.To give just one example, it is currently impossible to set
line-height
to a dynamic value based on the current font size, unless...font-size
is set on the same element as theline-height
(in which case you can useem
or%
), but that defeats the purpose of making it dynamic;calc()
and other math functions (min()
,max()
,clamp()
, etc.).Percentages would work, if it wasn't for the fact that
line-height
's use of percentages was "broken" (they exceptionally don't get preserved, just likeem
). To better explain why this is annoying, consider the following CSS / design intention:I also made the following Codepen to show how none of the current font-size-relative units get preserved during inheritance: https://codepen.io/benface/pen/XWOVyJx
Thanks!