With css, you can easily use ellipsis, but only at the end of the text.
However, there is a jQuery plugin called dotdotdot that can do this.
Here is the page: DotDotDot
One of their demos shows how a long URL can be converted to www.website.com/that/should/... /file.html
I spent some time trying to get this to work correctly, and it is still not quite perfect, but it works very well.
// @param element obtained with $("selector") // @param spacer ' ' for text, or '/' for links. // @param position number of words to leave at end function doEllipsis(element, spacer, position) { $(element).data('ell-orig', $(element).html()); $(element).data('ell-spacer', spacer); $(element).data('ell-pos', position); var pieces = $(element).html().split(spacer); if (pieces.length > 1) { var building = ""; var i = 0; // for "position" to mean "fraction where to wrap" (eg. 0.6), use this: // for (; i < pieces.length*position; i++) { for (; i < pieces.length-position; i++) { building += pieces[i] + spacer; } building += '<span class="ell">'; for (; i < pieces.length; i++) { building += pieces[i] + spacer; } building += '</span>'; $(element).html(building); $(element).dotdotdot({ after: 'span.ell', wrap: 'letter' }); } } // use to redraw after the size changes etc. function updateEllipsis(element) { var orig = $(element).data('ell-orig'); var spacer = $(element).data('ell-spacer'); var pos = $(element).data('ell-pos'); $(element).trigger("destroy"); $(element).empty(); $(element).html(orig); doEllipsis(element, spacer, pos); }
Here's the script for this example (it uses a copy hosted on my Dropbox, so itβs pretty sure that it wonβt work forever).
He reacts (to some extent, one way or another) and puts the ellipsis exactly where you tell him.
source share