tags:

views:

39

answers:

2

Hi,

I have this table:

<table style="width: 512px; border-collapse: collapse;" cellspacing="0">
<tbody>
<tr>
<td style="background: #00f; height: 9px; width: 9px;"></td>
<td style="background: #0f0; height: 9px;"></td>
<td style="background: #f00; height: 9px; width: 9px;"></td>
</tr>
</tbody>
</table>

Please no "do not use tables" kind of messages. I am using tables here for clarity, trying to solve my issue.

The problem is that I see the result as http://ioj.com/v/if64c

Where is the green line? It should be 496x9!

+3  A: 

If you add

table-layout: fixed;

to your table's css, it works.

(ref here)

This is because tables will auto-calculate column width based on cell contents by default.

sje397
Yep, use `table-layout: fixed` wherever possible. It is faster to render and much more predictable cross-browser than the default ‘auto’ table layout algorithm.
bobince
I did not know about this, this is also solves another issues I have had with tables earlier! Thanks so much for this wonderful answer. :)
rFactor
A: 
<table style="width: 512px; border-collapse: collapse;" cellspacing="0">
<tbody>
<tr>
<td style="background: #00f; height: 9px; width: 9px;"></td>
<td style="background: #0f0; height: 9px; width: 9px;"></td><!-- use specific width -->
<td style="background: #f00; height: 9px; width: 9px;"></td>
</tr>
</tbody>
</table>
Sadat