I have an example of a simple HTML table that contains a number of div blocks.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head></head>
<body>
<table border=1 width="1000px" >
<tr><td></td><td></td><td></td><td></td></tr>
<tr valign="top"><td colspan="1" ><div style="width:180px;border: solid 1px black;">1</div></td><td colspan="3" ><div style="width:770px;border: solid 1px black;">2</div></td></tr>
<tr valign="top"><td colspan="4" ><div style="width:960px;border: solid 1px black;">3</div></td></tr>
<tr valign="top"><td colspan="2" ><div style="width:475px;border: solid 1px black;">4</div></td><td colspan="2" ><div style="width:475px;border: solid 1px black;">5</div></td></tr>
</table>
</body>
</html>
The problem is that the look of row 2 is not correct. The colspans are not behaving as expected. If I remove the fourth line then the second behaves correctly.
I am aware that divs and CSS is the way to go but for this application, at this time, this is not possible.
Your problem is auto table layout. It’s hard for a browser to look at all the cells and work out how much width each is going to get from their content; it’s double-hard when there are colspans (especially in this example where there’s no way to tell how wide columns 3 and 4 should be at all); and it’s triple-hard when you’re poor old hard-of-thinking Internet Explorer, bless.
Don’t make your browser struggle, wheeze and render slowly: use
fixedtable-layoutand declare the width of every column exactly. Normally this would be done with<col>elements:However there is a bug in Webkit that ignores
<col>widths when there is no single unspanned cell in that column. This is quite unusual for tables, but it is the case in the above example: only the first column contains an unspanned cell. To work around it, you can either replace the<col>elements with a dud row at the start, styled to have minimal height:Or, sometimes less intrusive, keep the
<col>s and add a dud row at the bottom: