I had to smile when I saw your question... not that it is a stupid question, but during my own project I found it next to impossible to determine the width of the table.
Point is, the algorithm to determine the table and cell width is very complicated. And once you figured it out, you'll notice that different browsers have interpreted and implemented the algorithm completely different. Specifying column widths in <td> or <col> tags is nice, but it is overruled by the contents of the cells. The algorithm is described on the w3c.org web site.
I have an application using fixed font sizes as specified using CSS, and still my table look completely different in IE, Opera, Firefox and Epiphany. Even from one version to the other it is different...
If you use an iframe, at least *that* width is fixed.
My best results so far I had by:
- Specifying a width of 100% in the <table> tag so the table fills the iframe (in my case I used CSS boxes)
- Specifying the column width using the CSS width specifier, like:
Code:
<td align="center" valign="center">
<span class="time1" style="text-align : center; width: 55px;">
Your text goes here
</span>
</td>
Now I am sure that the text width is not more than 55 pix, if it gets larger, it will not expand the column size, but wrap in the span.
- After you set an exact size for all columns in this way, allow one column to expand and contract freely to adapt to browser differences. You can minimize this effect by making your frame width slightly larger than the sum of all widths. Be sure to add cell padding and border widths to all cells.
This is what gave me the most satisfying solution. Beware though that if you have just one cell without the <span> tag specifying the width, and the text is larger than the column width, your carefully designed table *will* expand at that column.
BTW, the align specifiers in the <td> tag specify how the span is aligned in the cell, but how not the text is aligned. And another nice thing to know, if your cell width becomes less than the span width (for example you aggregate span widths are more than the table width), the alignment within the span is spoiled. That is, in some browsers, not in all.
jlinkels