HTML 表格可以在行上有可变数量的单元格吗? [英] Can HTML table have variable number of cells on rows?

查看:12
本文介绍了HTML 表格可以在行上有可变数量的单元格吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

或者单元格总数应该等于columns * rows?

Or should the total amount of cells equal to columns * rows?

在不同行上具有不同数量单元格的表格似乎通过了 W3 验证器.

A table with different amount of cells on different rows seems to pass the W3 Validator.

推荐答案

那不违反定义.但是你应该使用 colspan 属性将列扩展到整行:

That does not violate the definition. But you should use the colspan attribute to expand the column to the whole row:

<table>
  <tr>
    <td>Row with</td>
    <td>2 cols</td>
  </tr>
  <tr>
    <td colspan="2">Row with only one col</td>
  </tr>
</table>

如果您在单元格周围设置边框,这也会有所帮助.

That will also help if you have borders around the cells.

您甚至可以拥有一列扩展为两行的表格:

You can even have tables with a column that expands to two rows:

<table>
  <tr>
    <td rowspan="2">First column in row 1 and row 2</td>
    <td>Second column in row 1</td>
  </tr>
  <tr>
    <td>second column in row 2</td>
  </tr>
</table>

这篇关于HTML 表格可以在行上有可变数量的单元格吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆