Is there any simple way to trim overflowing text, like the CSS text-overflow
property does, but which trims at word boundaries only?
I thought this would be a common problem with lots of material already existing, but surprisingly after searching I can't find any leads. Might be using wrong search terms.
If possible I'd prefer to to avoid JS for this. The basics would be easy, but to do it robustly I've got a feeling it would require a lot of ongoing event monitoring and width recalculating for cases such as if text changes, if browser window size changes, if text is initially invisible then is shown, if the layout changes, if a web font is used causing the text width to change once the font file is loaded, in some browsers, etc etc.
For example, so that if this text overflows...
Book a holiday in sunny Scunthrope!
It would be...
Book a holiday in sunny...
...and could never be...
Book a holiday in sunny Scunt...