单元格合并行列需要使用colspan和rowspan属性。例如,合并2行2列的单元格:

<table>
  <tr>
    <th>姓名</th>
    <th>性别</th>
    <th>年龄</th>
    <th>城市</th>
  </tr>
  <tr>
    <td rowspan="2">张三</td>
    <td>男</td>
    <td>25</td>
    <td>北京</td>
  </tr>
  <tr>
    <td>女</td>
    <td>23</td>
    <td>上海</td>
  </tr>
  <tr>
    <td>李四</td>
    <td>男</td>
    <td colspan="2">广州</td>
  </tr>
</table>

在第一个tr中,第一个单元格使用了rowspan="2",表示要合并2行。在第二个tr中,第一个单元格留空,因为它已经被第一个单元格合并了。第三个tr中,第三个单元格使用了colspan="2",表示要合并2列。

HTML单元格合并行列代码

原文地址: https://www.cveoy.top/t/topic/c00Y 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录