Locked lesson.
About this lesson
Exercise files
Download this lesson’s related exercise files.
Advanced Tables.docx59.5 KB Advanced Tables - Solution.docx
59.9 KB
Quick reference
Advanced Tables
Spanning more than one row or column in your table is pretty easy.
When to use
Anytime you would like a <th> or a <td> element to span more than one row or column.
Instructions
Use the colspan attribute to span more than one column:
<table>
<tr>
<th colspan="4" bgcolor="#ccc">My hiking log</th>
</tr>
<tr>
<th>Header 1</th>
<th>Header 2</th>
<th>Header n</th>
</tr>
<tr>
<td>Column of Data 1</td>
<td>Column of Data 2</td>
<td>Column of Data n</td>
</tr>
</table>
Use the rowspan attribute to span more than one row:
<table>
<tr>
<th colspan="5" bgcolor="#ccc">My hiking log</th>
</tr>
<tr>
<th>Category</th>
<th>Header 1</th>
<th>Header 2</th>
<th>Header n</th>
</tr>
<tr>
<th rowspan="2" bgcolor="#ccc">Hikers</th>
<td>Column of Data 1</td>
<td>Column of Data 2</td>
<td>Column of Data n</td>
</tr>
<tr>
<td>Column of Data 1</td>
<td>Column of Data 2</td>
<td>Column of Data n</td>
</tr>
</table>
Hints & tips
- To allow an element to span more than one column, use the colspan attribute.
- To allow an element to span more than one row, use the rowspan element.
- To give your table a border, give the table tag a border attribute set equal to the size border you want.
Lesson notes are only available for subscribers.