This is my situation :
The issue :
200px
)Hint :
very very very long line
to something like very very very ...
is what I'm thinking. Is something like that even possible? Server-side?How would you approach that? (preferably in an elegant way - 'coz, yep, I admit that I have a few solutions in mind, none of which seems... user-friendly... lol)
I think doing a string-truncation is impossible serverside, if you are not using a monospace font so that the same number of characters always has the same width. What you could do is a client-side string-truncation:
(Nice code at Calculate text width with JavaScript):
CSS:
#testing-div
{
position: absolute;
visibility: hidden;
height: auto;
width: auto;
}
JS:
var test = document.getElementById("testing-div");
test.style.fontSize = fontSize;
var height = (test.clientHeight + 1) + "px";
var width = (test.clientWidth + 1) + "px";
You can loop through the entire length of the string, and keep adding a character to the body of #testing-div
, calculating the width, and checking if it fits. Make sure you add the ...
if the string is too long.