user1084509
user1084509

Reputation: 1902

How to truncate HTML String keeping fixed column size

How can the fixed column width could be respected even when the strings are too long?

The thing is that I want to present a report in a jsp, but I separate the headers in a table and the content in another table, giving them both the same width to its columns. The problem is that the text in several columns is too long, so I want to know if it is possible to simply truncate the String to avoid the column from getting bigger.

I would appreciate your help.

Upvotes: 3

Views: 4003

Answers (2)

robertc
robertc

Reputation: 75717

You could try text-overflow: ellipsis:

td {  
  white-space: nowrap;                      
  overflow: hidden;              /* "overflow" value must be different from "visible" */    
  text-overflow: ellipsis;  
}  

Warning: Older versions of IE do weird things if you don't set explicit widths on your columns,

Upvotes: 4

Shai Mishali
Shai Mishali

Reputation: 9392

You could use CSS's overflow to truncate the content of an element to its parent's size.

#myDiv{
    width: 200px;
    height: 200px;
    overflow: hidden;
}

<div id="myDiv">bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla</div>

Shai.

Upvotes: 2

Related Questions