Re: [csswg-drafts] [css-sizing] How to shrink to fit the width? (#191)

@kizu thank you for such a cool idea with anchor positioning! Your writing once again helped me achieve what I thought was impossible (unrelated but the other time was coding data in SVG aspect ratio which allowed me to set stroke width, huge!).

I think I've managed to solve the classic flexbox problem:

<img width="592" height="154" alt="Image" src="https://github.com/user-attachments/assets/af01b9a1-c8fa-4d3a-88ef-0cb50e902390" />


In 4 steps:
1. Measure size of the middle text container
2. Measure size of the text using anchor
3. Subtract extra space from max-width
4. Add same amount as negative margin to the container so that its width remains the same and we do not go into an infinite loop of contracting and expanding

https://codepen.io/waterplea/pen/GgjoBxe

If only I could find a way for this to not involve parent container at all so I could isolate all the logic inside the `DIV` in question. But that's still good enough for me, I guess, and does not break anything in older browsers.

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


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

Received on Thursday, 5 March 2026 05:11:40 UTC