29.1.08

Inverse-Proportioned Columns

Today I accidentally blew my mind with a table layout. Given the following [simplified/spare me validation] code:


<table border=1>
<tr>
<td width=50%>hello</td>
</tr>
</table>


If you decrease the width of the column, you'll see the table grow. If you increase it (up to 100%), you'll see the table shrink. Get it? reduce the width and the thing grows!

The explanation is simple, however. When a table layout is auto and a column is defined in percentage, the table width is calculated as the column width multiplied by the inverse of its percentage. In other words, a 20% cell will occupy 1/5 of the table's width. This logic is loosely based on the assumption that you'll have the corresponding number of cells per row (in this case, 5), but it certainly isn't required to do so.

Verdict: USELESS

No comments: