More on table structure

This page is marked as In Progress so expect small errors or unfinished bits

THEAD and TFOOT

To properly structure a table you would need a heading row, data rows and perhaps a footer (perhaps containing totals). To achieve this you wrap a THEAD element around the first TR and the TH cells you should already have. Then TBODY around the rest of the rows and TDs. Weirdly, the TFOOT row is supposed to go immediately after the THEAD and before the TBODY.

Nested tables

Traditionally this technique has been used for laying out pages. That is no longer done so you may never need to put one table inside another. If you do display lots of data though it might be useful. Literally just put the new table inside the TD element where you want it. It is structured exactly the same way as a normal table.

Take one of your tables and insert a new table inside one of the TDs. Good indenting of your code helps keep track of the nested elements.

Merging cells

It is possible to merge two or more cells in a table into one. For example this:

<table summary="A table using colspan">            
    <tr>            
        <th colspan="3">Stock list                
        </th>
    </tr>
    <tr>
        <th>Fruit    
        </th>
        <th>Price
        </th>
        <th>Quantity
        </th>
    </tr>    
    <tr>
        <td>Apple
        </td>
        <td>50p
        </td>
        <td>1Kg    
        </td>
    </tr>
    <tr>
        <td>Orange
        </td>
        <td>60p
        </td>
        <td>1Kg
        </td>
    </tr>
</table>
        

creates this:

Full stock list
Fruit Price Quantity
Apple 50p 1Kg
Orange 60p 1Kg

Just take out a TD when you span a TD into two, take out two when you span to three. ROWSPAN does the same but this time the TD is removed from the following rows.

submit to reddit Delicious Tweet