Week 4: Structuring Data with Tables
Learn how to present tabular data effectively using HTML tables.
Explore Chapter 4Spanning Rows and Columns
Sometimes, a cell needs to span across multiple columns or rows. This is achieved using the `colspan` and `rowspan` attributes on <td> or <th> elements.
- `colspan="number"`: Makes the cell span horizontally across the specified `number` of columns.
- `rowspan="number"`: Makes the cell span vertically across the specified `number` of rows.
Example: Spanning
<table border="1">
<tr>
<th>Time</th>
<th>Monday</th>
<th>Tuesday</th>
</tr>
<tr>
<th>9:00 AM</th>
<td>Meeting</td>
<td rowspan="2">Project Work</td> <!-- Spans 2 rows -->
</tr>
<tr>
<th>10:00 AM</th>
<td>Break</td>
<!-- Cell for Tuesday 10:00 is covered by rowspan -->
</tr>
<tr>
<th>11:00 AM</th>
<td colspan="2">Team Sync</td> <!-- Spans 2 columns -->
</tr>
</table>
Renders as:
| Time | Monday | Tuesday |
|---|---|---|
| 9:00 AM | Meeting | Project Work |
| 10:00 AM | Break | |
| 11:00 AM | Team Sync | |