In HTML, the colspan and rowspan attributes are used to control the number of columns and rows a cell should span, respectively, in a table. Here's how they work:
colspan Attribute
- The
colspanattribute is used to make a table cell span multiple columns. - It specifies how many columns a cell should cover.
- The value of
colspanis the number of columns to span.
rowspan Attribute
- The
rowspanattribute is used to make a table cell span multiple rows. - It specifies how many rows a cell should cover.
- The value of
rowspanis the number of rows to span.
Example of Using colspan and rowspan:
<table border="1">
<tr>
<th>Header 1</th>
<th>Header 2</th>
<th>Header 3</th>
</tr>
<tr>
<td rowspan="2">Row 1, Column 1 (spans 2 rows)</td>
<td colspan="2">Row 1, Column 2 and 3 (spans 2 columns)</td>
</tr>
<tr>
<td>Row 2, Column 2</td>
<td>Row 2, Column 3</td>
</tr>
</table>
Explanation:
- In the first row, the second cell spans two columns using
colspan="2". - In the second row, the first cell spans two rows using
rowspan="2". - The table adjusts to combine cells where needed.
This results in a table with merged cells both horizontally and vertically.
No comments:
Post a Comment