I\'m trying to create a word-wrap in JavaScript using CSS, and the condition is:
If DIV contains one very long word, such as \"asdasfljashglajksgkjasghk
when you'll be allowed to use jQuery you could see the dotdotdot plugin at this link.. very simple to use and it works great!
For the moment i can suggest you to have a look at this fiddle! whould work the text-overflow: ellipsis
Displaying the ellipsis needs to be handled differently when the width of container is fixed and percentage.
.nooverflow{
display: inline-block;
overflow: hidden;
overflow-wrap: normal;
text-overflow: ellipsis;
white-space: nowrap;
}
.nooverflow{
display: inline-block;
overflow: hidden!important;
overflow-wrap: normal;
text-overflow: ellipsis;
white-space: nowrap!important;
width: 0;
min-width: 100%;
}
I know I'm a bit late with the anwser but I just wrote a pice of code that accomplices that:
if ($('your selector').height() > 50) {
var words = $('your selector').html().split(/\s+/);
words.push('...');
do {
words.splice(-2, 1);
$('your selector').html( words.join(' ') );
} while($('your selector').height() > 50);
}
and of course you should save the jQuery selector in a variable so you don't query the DOM every time.