Fixing Maximum Size for a Table Cell

Psumonix
Psumonix used Ask the Experts™
on
How can one fix the maximum size on a table cell, regardless of the text that is put into that cell.  A more specific question would be how to keep a cell from expanding beyond its fixed width when the text in the cell is too long and cannot wrap because it doesn't have any spaces.

Thanks in advance.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
You can suggest that the browser overflow the text beyond the edges of the cell and provide scrollbars instead.

<td style="width: 10em; height: 2em; overflow: auto;">

This won't work too well in Opera which will treat it as overflow: hidden instead.

Most people I've encountered who want to do this are trying to deal with a system that allows user input and users who put insanely long text strings in. The better way to deal with this is to validate the input data.
Just do something like:
Just be sure to use a fixed width, not percentage.

<table width="300" cellpadding="2" cellspacing="0" border="0">
  <tr>
    <td>
Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text  Some text
    </td>
   </tr>
</table>


Hope this helps,
 - Justin
Also, If you want it to not wrap the text just add the nowrap to it, like:

<td nowrap>

And if you have a table with mutliple columns and you want one col fixed just do something like

<table width="100%" cellpadding="4" cellspacing="0" border="0">
<tr>
<td width="150">
Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text
</td>
<td width="100%">
Some text Some text Some text Some text Some text Some text Some text Some text  Some text Some textSome text
</td>
</tr>
</table>
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Author

Commented:
You're correct, dorward.  I am indeed dealing with users who put insanely long strings in.  Unfortunately, this has to be allowed.  The problem here is that the search routine dumps all the fields into a table.  The table is a fixed width (600 pixels), and I need to keep it at that exact size.  If your answer (comment) was proposed so that I would change the width of the table, I am unable to do so.  As for the overflow setting, it never seems to have any effect in tables (at least on IE6).  I've also attempted the overflow:hidden, but have had no luck thus far.  I'm honestly not entirely sure why this isn't working, as I've seen it done relatively easy within div tags.
Psumonix, you can place a DIV inside the TD for the TABLE and set the overflow of this if it does not work directly?

Commented:
Overflow should work when applied to table data *cells*, even in Internet Explorer, but you do have to specify a height and width using CSS for it to be effective, although you don't have to use ems as the unit (they are just preferred as px isn't a very helpful unit when it comes to text).
<DIV style="OVERFLOW-X:auto; WIDTH:195px; HEIGHT:100px">
     <table>
         <tr><td>Bla BlaBla BlaBla laBlaBlaBlaBlaBlaBlaBla BlaBla BlaBla BlaBla BlaBla BlaBla BlaBla BlaBla BlaBla BlaBla BlaBla BlaBla BlaBla Bla dsflksdjfsldkfjsdlfjsd</td></tr>
         <tr><td>Bla Bla Bla BlaBla BlaBla BlaBla BlaBla BlaBla BlaBla BlaBla BlaBla BlaBla BlaBla BlaBla BlaBla BlaBla Bla</td></tr>
         <tr><td>Bla BlaBla BlaBla BlaBla Bla BlaBla BlaBla BlaBla BlaBla BlaBla BlaBla BlaBla BlaBla BlaBla BlaBla BlaBla BlaBla BlaBla BlaBla BlaBla BlaBlaBlaBla BlaBlaBlaBlaBlaBlaBlaBla BlaBlaBlaBlaBlaBlaBlaBlaBlaBla BlaBlaBlaBlaBlaBla BlaBlaBlaBla BlaBla BlaBla BlaBla BlaBla BlaBla BlaBla BlaBla BlaBla BlaBla BlaBla BlaBla BlaBla BlaBla BlaBla BlaBla BlaBla BlaBla BlaBla BlaBla BlaBla BlaBla BlaBla BlaBla BlaBla BlaBla BlaBla BlaBla BlaBla BlaBla BlaBla BlaBla BlaBla BlaBla BlaBla Bla BlaBla BlaBla BlaBla BlaBla BlaBla BlaBla BlaBla BlaBla BlaBla BlaBla BlaBla BlaBla BlaBla BlaBla BlaBla Bla</td></tr>
    </table>
</DIV>
bla bla bla :p
the best way is to hide the long strings and display shorcut strings instead. this can be done by using scripts.

for example, the string is as long as this:
http://www.experts-exchange.com/Web/Web_Languages/HTML/Q_20400936.html

you can make a script to display it this way:
http://www.experts-<<more>>

just a suggestion...
the best way is to hide the long strings and display shorcut strings instead. this can be done by using scripts.

for example, the string is as long as this:
http://www.experts-exchange.com/Web/Web_Languages/HTML/Q_20400936.html

you can make a script to display it this way:
http://www.experts-((more))

just a suggestion...

This is a shot in the dark, but maybe this could help you out:

<%
Function WordWrap(originalString, MaxWordLength)
Dim tempWord, longWord, items, i

items = Split(originalString)

For i = 0 To UBound(items)
 longWord = ""
 tempWord = items(i)

 Do While Len(tempWord) > MaxWordLength
   longWord = longWord & Left(tempWord, MaxWordLength) & "<br>"
   tempWord = Mid(tempWord, MaxWordLength + 1)
 Loop
 
 WordWrap = WordWrap & longWord & tempWord & " "
Next

WordWrap = Left(WordWrap, Len(WordWrap)-1)

End Function
%>


homewabbit
Top Expert 2013

Commented:
To get the overflow to work correctly in a table cell you have to fix the formatting of the table:

<table style="table-layout:fixed">


In most cases it is better to put the overflow attribute on a div inside of the cell, as overflow on a cell is much less dependable, and not as widely supported.

Cd&
Top Expert 2013

Commented:
If is is still a problem, then post a link so we can see if anything else in the page is going to create a problem.

Cd&

Author

Commented:
Hmpf.  For some reason, I can't get this to work at all.  I actually ended up modifying the perl to automatically truncate and add ellipses.  Points to dorward for giving the answer that would have worked, were I not so inept.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial