html - HTML 表格可以在行上有可变数量的单元格吗?

标签 html html-table

或者单元格总数是否应该等于列 * 行

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

最佳答案

这并不违反定义。但是你应该使用 colspan将列扩展到整行的属性:

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

如果单元格周围有边框,这也会有所帮助。

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

<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 - HTML 表格可以在行上有可变数量的单元格吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3484768/

相关文章:

javascript - 如何在显示通知 DIV 时将 "dim"网页的其余部分?

jQuery 空很慢

jquery - 为什么 <button> 也会触发表单提交

django - 将 Django 模型输出为表格

jquery - 如何根据在 jquery 文本框中扫描的值在行列表中交换特定行

html - 完全可点击的表格单元格中的居中文本

jquery - 使用 jQuery 对 HTML 表格行进行自定义排序

html - 无法更改导航栏的背景颜色

javascript - Iframe 内容不显示在 IE 上

javascript - 可以覆盖多个模块吗?