How can I force clipping of text in a table cell?

J

john

I want to set the cell width and height such that the cell doesn't get
bigger. If the text is too long for the cell, it should be clipped. It
only has to work for IE. I have tried setting the overflow style to
hidden, but that doesn't work unless I set the table-layout style of
the table to fixed, which I cannot do. In the sample code below, it
correctly sets the width of the cell to 200, but the height gets
bigger and it wraps the text. If I add a <nobr> tag to the cell, the
text doesn't wrap any more, but the width gets real big (enough to fit
all the text).

<table width="200" border="1">
<tr>
<td height="20" width="200" id="tableCell" style="overflow:hidden">
So, here is some text that obviously will not fit in this lousy 200
pixel wide box.
</td>
</tr>
</table>

Thanks in advance.
 
A

alan.washington

Not sure this is the best forum for this but I will answer with .Net solution.

Find out the make number of characters that can fit in the and use substring to trim those values.

For example:

string test = "this is a test that should only be 10 characters long";
test = test.Substring(0, 10);

This is assuming that your cell is wide enough to fit 10 characters.

Alan Washington
http://www.aewnet.com
I want to set the cell width and height such that the cell doesn't get
bigger. If the text is too long for the cell, it should be clipped. It
only has to work for IE. I have tried setting the overflow style to
hidden, but that doesn't work unless I set the table-layout style of
the table to fixed, which I cannot do. In the sample code below, it
correctly sets the width of the cell to 200, but the height gets
bigger and it wraps the text. If I add a <nobr> tag to the cell, the
text doesn't wrap any more, but the width gets real big (enough to fit
all the text).

<table width="200" border="1">
<tr>
<td height="20" width="200" id="tableCell" style="overflow:hidden">
So, here is some text that obviously will not fit in this lousy 200
pixel wide box.
</td>
</tr>
</table>

Thanks in advance

User submitted from AEWNET (http://www.aewnet.com/)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,832
Latest member
GlennSmall

Latest Threads

Top