Problem Statement
What does the rowspan attribute do in a table cell?
Explanation
The rowspan attribute makes a table cell span across multiple rows vertically. When you set rowspan to a number, that cell extends down through that many rows. For example, rowspan equals 3 means the cell spans three rows vertically. This is useful when you have data that applies to multiple rows, such as category labels or grouped information. When using rowspan, be careful with the number of cells in subsequent rows. If a cell from a previous row is spanning down, you need one fewer cell in the current row. Rowspan is commonly used for creating hierarchical tables, displaying grouped data, or showing information that applies to multiple entries. Understanding both colspan and rowspan is essential for creating complex table layouts.
Code Solution
SolutionRead Only
<!-- Cell spanning 2 rows -->
<table border="1">
<tr>
<td rowspan="2">Monday</td>
<td>Morning</td>
<td>Math</td>
</tr>
<tr>
<td>Afternoon</td>
<td>Science</td>
</tr>
</table>
<!-- Category spanning multiple items -->
<table border="1">
<tr>
<td rowspan="3">Fruits</td>
<td>Apple</td>
</tr>
<tr>
<td>Banana</td>
</tr>
<tr>
<td>Orange</td>
</tr>
<tr>
<td rowspan="2">Vegetables</td>
<td>Carrot</td>
</tr>
<tr>
<td>Broccoli</td>
</tr>
</table>