Forum Moderators: open
I like the idea of using a table to display this information. So, is using an HTML table the best way to do this? (I will style it with CSS)
And if so, how can I make it such that I can easily add a column to that table in the future? If I create the table with four <td></td>s and don't put anything in the cells that are to become the future fourth column, is there a way I can make the table look nice during the time it has only three items per line?
Tables should contract to the content, that is, if there's no content* the table should "squeeze" to whatever is there. So a simple solution would be:
CSS:
#mytable { margin: auto; }
#mytable td { padding: 6px; }
#mytable th {
padding: 6px; background:#000;
color: #fff;
font-weight:bold;
}
#mytable .empty {
padding:0;
width:0;
background:none;
font-size:2px;
}
<table id="mytable" cellspacing="0">
<tr>
<th>col 1</th>
<th>col 2</th>
<th class="empty"> </th>
<th class="empty"> </th>
</tr>
<tr>
<td> data 1a</td>
<td> data 1b</td>
<td class="empty"> </td>
<td class="empty"> </td>
</tr>
<tr>
<td> data 2a</td>
<td> data 2b</td>
<td class="empty"> </td>
<td class="empty"> </td>
</tr>
</table>
* Note the non breaking space in empty cells. IE abhors empty cells, making for weird looking tables at times. It also doesn't render anything smaller than 2px, which is why the extra coding for class "empty".
You may not even need the empty selectors if the table doesn't "explode" too much.