i want a table to render with minimum width according to its content, but IE7 insists on expanding it to 100% width.
The following little snippet works fine in Firefox and IE8, but not in IE7:
<!DOCTYPE HTML>
<html>
<head>
<style type="text/css">
table { table-layout: fixed }
td { padding: 0 10px; border: 1px solid blue;}
</style>
</head>
<body>
<table>
<tr>
<td>Column with variable width</td>
<td style="width: 100px;">Column 2</td>
<td style="width: 100px;">Column 3</td>
</tr>
</table>
</body>
</html>
- I have a table with table-layout: fixed.
- I have specified the width of all cells except the first one.
- In the first column, i want the browser to determine the width based on the content
- As I don’t know the width of the first column, I cannot (and do not want to) specify the width of the table.
Now, the problem in IE7 is that the table is rendered to 100% width. So the first col has not the minimum width that is required to display its content but takes up all the space to make the table 100% width.
Here is what i found out so far:
- when i remove “table-layout: fixed” from the table, the table will not expand to 100%. Unfortunatly, that’s not an option for me.
- when i set the table-width to a very small size (like e.g. 10px), the first col will not be expanded to the minimum required width, but will disappear entirerly.
- i tried to set “display: inline;” for the table, but that has no effects on the width.
Any ideas?
Thanks in advace,
Pitter
If only purpose of
table-layout: fixedis to fix widths of cells, then you can addDIVs with desired width insideTDand get rid oftable-layout: fixedfor table.