0

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...

Simple jsbin demo

user56reinstatemonica8
  • 32,576
  • 21
  • 101
  • 125
  • Great, that didn't come up in any of my searches for some reason. That question is from 2012, presumably there's nothing new since then (including ready-made JS libraries?) – user56reinstatemonica8 Sep 15 '14 at 11:58
  • Check if [this plugin](http://pvdspek.github.io/jquery.autoellipsis/) helps. I have not tried it but just saw in search. – Harry Sep 15 '14 at 12:08
  • Cool, thanks, I also found the [dotdotdot](http://dotdotdot.frebsite.nl/) plugin through browsing related questions to the linked question which is similar but also responsive - have added it as an answer to the linked dupe original. – user56reinstatemonica8 Sep 15 '14 at 12:10

0 Answers0