Click here to Skip to main content
15,888,461 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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!
Posted
Updated 8-Jul-10 14:21pm
v3

1 solution

Add CSS Class

CSS
.ellipsis span {
  white-space:nowrap;
   text-overflow:ellipsis; /* for internet explorer */
   overflow:hidden;
   width:190px;
   display:block;
}
html>body .ellipsis {
   clear:both;
}
html>body .ellipsis span:after {
   content: "...";
}
html>body .ellipsis span {
   max-width:180px;
   width:auto !important;
   float:left;
}


And HTML is

XML
<div class="ellipsis">
     <span>wwwwwwwwwwgfdgdfgdfgdfgfdgdfgdfgxgsdgsdfgdfgfdgdfgdfgdfgdfgdfg</span>
</div>
 
Share this answer
 
Comments
_iobuf 9-Jul-10 13:10pm    
Reason for my vote of 5
Thank you! Worked great!
_iobuf 9-Jul-10 13:13pm    
Is there any way to remove the ... if the text is shorter than the max width?
_iobuf 9-Jul-10 13:15pm    
Nevermind... I just removed the content: "..."; property and the browser handled the rest.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900