ajsefk
09-16-2005, 03:35 PM
Hi, I am trying to build a table of a specific width, relative to the window size, containing equally-sized table cells (TDs).
The content of these table cells is not known in advance (this is generated HTML). The trouble occurs when the TD content is long, thus widening the table cell and distorting the layout.
What I would LIKE to happen is for the TDs to retain their natural widths, but for the content within the TD to be CLIPPED. I tried using overflow:hidden, and various other CSS properties, but no luck.
The other restriction is that the text cannot wrap; it must use only a single line.
The whole thing is demonstrated by the following HTML (also present here, at http://www.geocities.com/asefkow/css/tablewidth.htm). The content is long, because it contains a description of the problem.
I would appreciate any help with this!
-Andy
---------------
<html>
<head>
<title>css test</title>
<style type="text/css">
td {
white-space:nowrap;
overflow:hidden;
text-overflow:ellipsis;
border:1px solid blue
}
</style>
</head>
<body style="font-family:tahoma">
<p>The table is supposed to be 80% of the window width; each TD is 50% of that.</p>
<table border=1 style="width:80%">
<tr>
<td style="width:50%">this is some short text</td>
<td style="width:50%">this is some much much longer text that makes this column really wide so that the table is much more than 80% of the screen</td>
</tr>
<tr>
<td style="width:50%">more text</td>
<td style="width:50%">more text</td>
</table>
<br>
<p>but the columns widths are not equal, and the table is wider than 80% typically. Here's the same table, but with short text.</p>
<table border=1 style="width:80%">
<tr>
<td style="width:50%">this is some short text</td>
<td style="width:50%">short text this time</td>
</tr>
<tr>
<td style="width:50%">more text</td>
<td style="width:50%">more text</td>
</tr>
</table>
<br>
<p>and once again with only spaces, to emphasize the point</p>
<table border=1 style="width:80%">
<tr>
<td style="width:50%"> </td>
<td style="width:50%"> </td>
</tr>
<tr>
<td style="width:50%"> </td>
<td style="width:50%"> </td>
</tr>
</table>
<br>
<br>
<p style="font-weight:bold">I would like to use CSS to clip the content of each cell, so that the table is 80% of the window width, and the two cells are equal in width (both 50% of the table). Basically, I need a way for the text to occupy only the width that the TD would normally use (i.e. for the TD to be as wide with the text as without it). I want the first table to have the same geometry as the 2nd and 3rd tables.</p>
<br>
<br>
<p>I realize I can do this with absolute width (e.g. 200px) SPANs in each TD, but I want the TD content to fill as much of the cell as possible</p>
<table border=1 style="width:80%">
<tr>
<td style="width:50%"><span style="width=200px;overflow:hidden;text-overflow:ellipsis">this is text longer than 200px generally</span></td>
<td style="width:50%"><span style="width=200px;overflow:hidden;text-overflow:ellipsis">this is some long long long long long long long long long long text</span></td>
</tr>
</table>
<br>
<br>
<br>
<p>rulers</p>
<div style="width:40%;background-color:green;color:white">40%</div>
<div style="width:80%;background-color:green;color:white">80%</div>
<br>
<div style="width:100px;background-color:red;color:white">100px</div>
<div style="width:200px;background-color:red;color:white">200px</div>
<div style="width:300px;background-color:red;color:white">300px</div>
<div style="width:400px;background-color:red;color:white">400px</div>
<div style="width:500px;background-color:red;color:white">500px</div>
<div style="width:600px;background-color:red;color:white">600px</div>
<br>
<br>
<a href="mailto:asefkow AT yahoo DOT com">asefkow AT yahoo DOT com</a>
The content of these table cells is not known in advance (this is generated HTML). The trouble occurs when the TD content is long, thus widening the table cell and distorting the layout.
What I would LIKE to happen is for the TDs to retain their natural widths, but for the content within the TD to be CLIPPED. I tried using overflow:hidden, and various other CSS properties, but no luck.
The other restriction is that the text cannot wrap; it must use only a single line.
The whole thing is demonstrated by the following HTML (also present here, at http://www.geocities.com/asefkow/css/tablewidth.htm). The content is long, because it contains a description of the problem.
I would appreciate any help with this!
-Andy
---------------
<html>
<head>
<title>css test</title>
<style type="text/css">
td {
white-space:nowrap;
overflow:hidden;
text-overflow:ellipsis;
border:1px solid blue
}
</style>
</head>
<body style="font-family:tahoma">
<p>The table is supposed to be 80% of the window width; each TD is 50% of that.</p>
<table border=1 style="width:80%">
<tr>
<td style="width:50%">this is some short text</td>
<td style="width:50%">this is some much much longer text that makes this column really wide so that the table is much more than 80% of the screen</td>
</tr>
<tr>
<td style="width:50%">more text</td>
<td style="width:50%">more text</td>
</table>
<br>
<p>but the columns widths are not equal, and the table is wider than 80% typically. Here's the same table, but with short text.</p>
<table border=1 style="width:80%">
<tr>
<td style="width:50%">this is some short text</td>
<td style="width:50%">short text this time</td>
</tr>
<tr>
<td style="width:50%">more text</td>
<td style="width:50%">more text</td>
</tr>
</table>
<br>
<p>and once again with only spaces, to emphasize the point</p>
<table border=1 style="width:80%">
<tr>
<td style="width:50%"> </td>
<td style="width:50%"> </td>
</tr>
<tr>
<td style="width:50%"> </td>
<td style="width:50%"> </td>
</tr>
</table>
<br>
<br>
<p style="font-weight:bold">I would like to use CSS to clip the content of each cell, so that the table is 80% of the window width, and the two cells are equal in width (both 50% of the table). Basically, I need a way for the text to occupy only the width that the TD would normally use (i.e. for the TD to be as wide with the text as without it). I want the first table to have the same geometry as the 2nd and 3rd tables.</p>
<br>
<br>
<p>I realize I can do this with absolute width (e.g. 200px) SPANs in each TD, but I want the TD content to fill as much of the cell as possible</p>
<table border=1 style="width:80%">
<tr>
<td style="width:50%"><span style="width=200px;overflow:hidden;text-overflow:ellipsis">this is text longer than 200px generally</span></td>
<td style="width:50%"><span style="width=200px;overflow:hidden;text-overflow:ellipsis">this is some long long long long long long long long long long text</span></td>
</tr>
</table>
<br>
<br>
<br>
<p>rulers</p>
<div style="width:40%;background-color:green;color:white">40%</div>
<div style="width:80%;background-color:green;color:white">80%</div>
<br>
<div style="width:100px;background-color:red;color:white">100px</div>
<div style="width:200px;background-color:red;color:white">200px</div>
<div style="width:300px;background-color:red;color:white">300px</div>
<div style="width:400px;background-color:red;color:white">400px</div>
<div style="width:500px;background-color:red;color:white">500px</div>
<div style="width:600px;background-color:red;color:white">600px</div>
<br>
<br>
<a href="mailto:asefkow AT yahoo DOT com">asefkow AT yahoo DOT com</a>