CSS question about text trimming
-
Hi, I am trying to add an elipsis for some text inside a div using css. for example, <div style="???????"> WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW </div> What I want is for the end result to look like: WWWWWW... Or at least just cut off without the .... The div is inside a td which stretches out when the text is too long, and making the td or div a fixed width is not an option. How can I do this? Thanks!
-
Hi, I am trying to add an elipsis for some text inside a div using css. for example, <div style="???????"> WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW </div> What I want is for the end result to look like: WWWWWW... Or at least just cut off without the .... The div is inside a td which stretches out when the text is too long, and making the td or div a fixed width is not an option. How can I do this? Thanks!
For width issue, you can set overflow property to hidden in style attribute.
<div id="myDiv" style="overflow:hidden; height:20px; width:200px;"> Some Long Text. </div>
If you wish to trim the text, use some javascript function on page load at client side.function Trim(id, len) {
document.getElementById(id).innerHTML = document.getElementById(id).innerHTML.substring(0, len) + "...";
}Hope this will help.
Anurag Gandhi.
http://www.gandhisoft.com
Life is a computer program and every one is the programmer of his own life.