←back to thread

2093 points pabs3 | 1 comments | | HN request time: 0s | source
Show context
albert_e ◴[] No.42136173[source]
> One small challenge was maximizing the size of the message text. Sometimes a message is just a word or two; other times it might be several sentences. A single font size can’t accommodate such a wide range of text content. I couldn’t find a pure CSS way to automatically maximize font size so that a text element with word wrapping would display without clipping.

> I ended up writing a small JavaScript function to maximize font size: it makes the text invisible (via CSS visibility: hidden), tries displaying the text at a very large size, and then tries successively smaller font sizes until it finds a size that lets all the text fit. It then makes the text visible again.

Wow -- not just for accessibility but this seems like a very useful feature to have in native CSS.

Nice find.

Overall such a heartwarming use of technology. Love.

replies(4): >>42136955 #>>42145091 #>>42145572 #>>42189463 #
1. niutech ◴[] No.42189463[source]
There is pure CSS solution: https://kizu.dev/fit-to-width/