colspan
和rowspan
这两个属性用于创建特殊的表格。
colspan
is the abbreviation for column span (cross-column). colspan
attribute is used in the TD label to specify the number of columns that the cell spans horizontally :
The following will be displayed in the browser:
Cell 1 |
Cell 2 |
Cell 3 |
Cell 4 |
The example colspan
is set to "3" so that the cell spans three columns. If we set it to colspan
"2", the cell will only span two columns, so it is necessary to insert another cell in the first row to ensure that the two rows occupy the same number of columns.
The example will appear in the browser as follows:
Cell 1 |
Cell 2 |
Cell 3 |
Cell 4 |
Cell 5 |
rowspan
Specifies the number of rows that the cell spans vertically .
The browser will appear as follows:
Cell 1 |
Cell 2 |
Cell 3 |
Cell 4 |
In the previous example, cell 1, which rowspan
is set to "3", means that the cell must span three rows (itself, plus two other lines). Therefore, cell 1 and cell 2 are on the same line, and cell 3 and cell 4 form two separate lines.
Comprehensive examples
<table border= "1" width= ">"
<tr>
<TD colspan= "4" >ss
</td>
</tr>
<tr>
<TD width= "25%" > </td>
<TD width= "25%" > </td>
<TD width= "25%" > </td>
<TD width= "25%" > </td>
</tr>
<tr>
<TD width= "25%" rowspan= "2" > </td>
<TD width= "25%" > </td>
<TD width= "25%" > </td>
<TD width= "25%" > </td>
</tr>
<tr>
<TD width= "25%" > </td>
<TD width= "25%" rowspan= "3" > </td>
<TD width= "25%" > </td>
</tr>
<tr>
<TD width= "25%" colspan= "2" > </td>
<TD width= "25%" > </td>
</tr>
<tr>
<TD width= "25%" > </td>
<TD width= "25%" > </td>
<TD width= "25%" > </td>
</tr>
</table>
Table merges cells colspan and rowspan.