Spanning columns: colspan
To create a colspan, use the colspan attribute with <td> or <th> tag. As an example, assume we want to create the following table:
Spanning columns | |
---|---|
Colspan | Combining at least two cells horizontally. |
In the first row, we are spanning two columns. Again, to create a table that spans rows or columns, first create the table structure:
<table width="400" border="1" cellpadding="2">
<tr>
<th></th>
<th></th>
</tr>
<tr>
<td></td>
<td></td>
</tr>
</table>
Again, we need to span the first cell in the first row. To span the first cell, simply place the colspan attribute in the first cell:
<th colspan="2"></th>
Because now our first column will span to the second cell in first row, we need to adjust our row. That means we need to have only one <th> tag. The following shows the complete HTML code to create the above displayed table:
<table width="400" border="1" cellpadding="2">
<tr>
<th colspan="2">Spannning columns</th>
</tr>
<tr>
<td>Colspan</td>
<td>Combining at least two cells horizontally.</td>
</tr>
</table>