Psumonix
asked on
Fixing Maximum Size for a Table Cell
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.
Thanks in advance.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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>
<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>
ASKER
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?
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 BlaBlaBlaBlaBlaBlaBlaBlaBl aBla 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>
<table>
<tr><td>Bla BlaBla BlaBla laBlaBlaBlaBlaBlaBlaBla BlaBla BlaBla BlaBla BlaBla BlaBla BlaBla BlaBla BlaBla BlaBla BlaBla BlaBla BlaBla Bla dsflksdjfsldkfjsdlfjsd</td
<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 BlaBlaBlaBlaBlaBlaBlaBlaBl
</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:
https://www.experts-exchange.com/questions/20400936/Convert-HTML-to-MS-Word.html
you can make a script to display it this way:
http://www.experts-<<more>>
just a suggestion...
for example, the string is as long as this:
https://www.experts-exchange.com/questions/20400936/Convert-HTML-to-MS-Word.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:
https://www.experts-exchange.com/questions/20400936/Convert-HTML-to-MS-Word.html
you can make a script to display it this way:
http://www.experts-((more))
just a suggestion...
for example, the string is as long as this:
https://www.experts-exchange.com/questions/20400936/Convert-HTML-to-MS-Word.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
<%
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
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&
<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&
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&
Cd&
ASKER
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.
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