LWD Ch08 Tables
LWD Ch08 Tables
TABLE MARKUP
OVERVIEW
• Table headers
• Table captions
NOTE: Columns are implied by the number of cells in each row (not
created with column elements).
HTML Table Structure (cont'd)
<table>
<tr>
<th>Menu item</th>
<th>Calories</th>
<th>Fat (g)</th>
</tr>
<tr>
<td>Chicken noodle soup</td>
<td>120</td>
<td>2</td>
</tr>
<tr>
<td>Caesar salad</td>
<td>400</td>
<td>26</td>
</tr>
</table>
The table Element
<table> </table>
<table>
<tr>
<th>Burgers</th>
<td>Organic Grass-fed Beef</td>
<td>Black Bean Veggie</td>
</tr>
<tr>
<th>Fries</th>
<td>Hand-cut Idaho potato</td>
<td>Seasoned sweet potato</td>
</tr>
</table>
Spanning Cells
Spanning
Stretching a cell to cover several rows or columns
Column span
Stretching a cell to the right over subsequent columns
Row span
Stretching a cell downward over several rows
Column Spans
Use the colspan attribute to specify the number of columns the cell
should span over:
<table>
<tr>
<th colspan="2">Fat</th>
</tr>
<tr>
<td>Saturated Fat (g)</td>
<td>Unsaturated Fat (g)</td>
</tr>
</table>
Notice that the first tr element only has one cell in it now. Every row
should have the same number of cells or equivalent colspan values.
Row Spans
The rowspan attribute to specifies the number of rows the cell
spans:
<table>
<tr>
<th rowspan="3">Serving Size</th>
<td>Small (8oz.)</td>
</tr>
<tr>
<td>Medium (16oz.)</td>
</tr>
<tr>
<td>Large (24oz.)</td>
</tr>
</table>
Notice that the td elements that were spanned over are no longer in
the source.
Table Caption
<caption> </caption>
<table>
<caption>Nutritional Information</caption>
<tr>
<th>Menu item</th>
<th>Calories</th>
<th>Fat (g)</th>
</tr>
…table continues…
</table>
Row and Column Groups
<table>
…
<thead>
<!-- headers -->
<tr></tr>
<tr></tr>
<tr></tr>
<thead>
<tbody>
<!-- data -->
<tr></tr>
<tr></tr>
<tr></tr>
<tr></tr>
<tr></tr>
<tr></tr>
</tbody>
<tfoot>
<!-- footnote -->
<tr></tr> NOTE: this table also utilizes
</tfoot>
</table> row and column spans.
Column Groups
<colgroup> </colgroup>
<col> </col>
<table> <colgroup></colgroup>
<caption>…</caption> <colgroup>
<colgroup></colgroup> <col class="start">
<colgroup span="2"></colgroup> <col class="end">
<colgroup span="2"></colgroup> </colgroup>
<colgroup>
<!-- rest of table... --> <col class="start">
<col class="end">
</colgroup>