Re: [csswg-drafts] [css-fonts-4] Feature for making text always fit the width of its parent (#2528)

I want us to return to this issue — we now have `inline-size` containment, which could be used to solve the potential issues regarding the circularity.

The list of things a potential solution for “fit to width” text should handle the following, in my opinion:

1. It should work only inside an element with `size` or `inline-size` containment.
2. We need to have an ability to set a min/max font-size.
    - We could use the existing font-size as the minimum — this would guarantee a) readable font-size when too much content/too narrow context, b) better graceful degradation.
    - I'd argue that introducing a new property instead of using something like `fit-width(8px, 48px)` value for the `font-size` could be more preferable: easier to detect the intent, easier to fall back to the regular font-size when you'd forget the containment/when the feature is not supported.
    - I think it is better to have a single property that would trigger the fit-to-width and set the maximum. Better to encourage having some limit, and someone who don't want to be limited could still set it to an arbitrary big number as a work-around.
3. Should work with multi-line text:
    - If multiple lines of text are present (with hard-breaks, like with `<br/>` or in `pre` context) the longest line should be used for this limit.
    - By default should fit as many text as can fit until meeting the `min` font-size, then wrap.
    - _Maybe_ there could be an option to force the “fit-to-width” on all the wrapped lines until they fit again — but only as an option, as both behaviors have use-cases.
    - Optionally, not sure if easy to implement — should work nicely with `text-wrap: balance`. Logically, with the simplest form of balancing, it sounds not super complicated: calculate the initial wrapping opportunity based on the min font-size, then balance things using the `text-wrap: balance`, then bump the size either based of the longest line for everything, or for each line separately, based on the preference from the previous item.


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


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

Received on Thursday, 23 March 2023 21:09:36 UTC