I have a web page that has an HTML table generated by an ASP.NET control. The top row of the table emulates a toolbar. That top row is laid out sort of like this:
<tr>
<td style="white-space:nowrap;">
<span>Very long title</span>
</td>
<td>
{ bunch of hyperlinks with background images, emulating a toolbar }
</td>
</tr>
I am stuck with the fact that this is a table, with the contents of the title area being put in a span, and probably with that inline style specifying no wrapping.
This table is supposed to narrow itself when the page narrows, and it does that pretty well. However, if the actual title text (which can vary) is too long, it effectively serves as a limit on how narrow the table can get, which can lead to overlapping with other things on the page. (I'm using IE8, BTW.)
I tried applying overflow:hidden
, text-overflow:ellipsis
, and display: inline-block
to the span and adding a width value for the table cell, all through a stylesheet. (Display:block
on the span doubled the height of the row, which I didn't want, so inline-block
was my choice.) The title text appeared truncated, just as I wanted. But the table wouldn't get any narrower.
After messing around changing values and styles through IEDT I concluded that, when figuring out how narrow the table could get, the text was still counted as being its full length. The span was relatively short, only the text that appeared in the span appeared, but for table-cell
width purposes, the text was still all there.
I didn't find this phenomenon documented anywhere, but maybe I just don't get around enough. :) If text-overflow
can't help me, I guess I'll have to dynamically truncate the title through script, which I'd rather not do. Is there a way to do what I want solely through CSS?
To manipulate the height or width of an entire table, place the size attribute (either "WIDTH=" or "HEIGHT=") within the <TABLE> code. To manipulate individual cells, place the size attribute within the code for that cell.
Use the CSS property width and height to set the width and height of the cell respectively. Just keep in mind, the usage of style attribute overrides any style set globally. It will override any style set in the HTML <style> tag or external style sheet.
Within the table-cell that you want to apply truncation, simply include a container div with css table-layout: fixed. This container takes the full width of the parent table cell, so it even acts responsive. Make sure to apply truncation to the elements in the table.
Table's cells display behavior differs from usual behavior of blocks. To make it more typical you need to change table's table-layout property to "fixed" first and set table width:
table { table-layout: fixed; width: 100%; }
It will disable cell's automatic sizing it most cases. After that you can set td's width and overflow as usual.
td.title { white-space:nowrap;overflow: hidden; width: 200px; }
Here is example: http://jsfiddle.net/vS3qq/1/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With