Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

truncate line that doesn't fit into fixed width <TD>? 1

Status
Not open for further replies.

msc0tt

IS-IT--Management
Jun 25, 2002
281
0
0
CA
I have a cgi (in Perl) that creates a table. If the data in one of the columns is longer than the column width, I want it to only display what will fit on a single line in the column. i.e.
<td width=&quot;50>This is a test this is a test this is a test</td>
In this example, I only want the first portion of the line that fully fits, to be displayed.
I've tried truncated the line in the cgi BEFORE it is output into the HTML, but this doesn't take into account proportionally spaced fonts (50 i's need less space that 50 w's).
I've tried nowrap=&quot;nowrap&quot;, but this just increased the column width to accomodate the full line.

-with thanks
 
Try this:

<td width=&quot;50 style=&quot;overflow:hide&quot;>This is a test this is a test this is a test</td>
 
Hmmm... still didn't work. Does this trick require spaces in the data? Here is the exact tag created by my cgi. In the browser, it splits the line after the second dash.

<td width=75 style=&quot;overflow:hide&quot;><font size=&quot;-1&quot;>r-56850956-492@vzjkzcmzj.lessthanyouthink.com</font></td>
 
Try
Code:
overflow:hidden
instead of
Code:
overflow:hide
.

Kevin
A+, Network+, MCP
 
Nope. Still didn't work.
Now, I know ZERO about style sheets. Is there something I need to put elsewhere in my page that enables these 'style' features in a tag?
 
I think what you'll need to do then is create a <div> inside of your <td> and specify a height, width, and overflow: hidden for the div.
Code:
<td><div style=&quot;width: 75px; height: 1em; overflow:hide&quot;><font size=&quot;-1&quot;>r-56850956-492@vzjkzcmzj.lessthanyouthink.com</font></div></td>

Specifying the width and height in the style like I did will allow you to set the height to the height of a character instead of trying to figure the height in pixels. I tested this code in IE and Mozilla and it appears to work in both. The only problem is with characters like 'y' with parts that hang down get cut off a little.

Kevin
A+, Network+, MCP
 
Well, what can I say. This still doesn't work for me. I'm using IE 6.0 SP1. The extract from &quot;View | Source&quot; is as follows:

<td><div style=&quot;width: 75px; height: 1em; overflow: hide&quot;><font size=&quot;-1&quot;>r-151394850-1579@tuvucjlevx.savvy-mail.com</font></div></td>

I'm stumped. Considering it works for you, I wonder if there is something else on my page that is hindering this solution???? (Note: the complete HTML source is almost 900 lines long...... so I don't think I'll post it! ;-{).
-Mike
 
Code:
<div id=&quot;hidden&quot; style=&quot;width:75px; overflow: hidden;&quot;><NOBR><a href=&quot;r-151394850-1579@tuvucjlevx.savvy-mail.com&quot;>r-151394850-1579@tuvucjlevx.savvy-mail.com</a></NOBR></div>

go to town on that -- to works here -- you need the &quot;NOBR&quot; tag that forces no breaks!

<Signature>
Sometimes the Answer You Are LOOKING for can be FOUND BY SEARCHING THE FAQ'S @&%$*#!!!
</Signature>
 
We have a winner! This now works perfectly! Thanks to all.
 
Hmm, I wonder if my solution didn't work because the code I posted mistakenly had &quot;hide&quot; instead of &quot;hidden&quot;.

FYI.. Though it appears most browsers support it, I believe NOBR is not part of the W3C's recommendations. Instead you can specify white-space: nowrap in the style for the <td>.

Kevin
A+, Network+, MCP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top