html - 表格行的不同宽度

标签 html css

我尝试拆分中间行并保持上行和底部不变。

<table border="1" width="500">
    <tbody>
        <tr bgcolor="red">
            <td width="10%">&nbsp;</td>
            <td width="80%">&nbsp;</td>
            <td width="10%">&nbsp;</td>
        </tr>
        <tr bgcolor="green">
            <td width="50%" colspan="2">&nbsp;</td>
            <td width="50%">&nbsp;</td>
        </tr>
        <tr bgcolor="blue">
            <td colspan="3">&nbsp;</td>
        </tr>
    </tbody>
</table>                                         

如何使用一个表格标签将中间行分成两列?

最佳答案

添加更多colspan:

table {
  width: 500px;
  table-layout: fixed;
  border: 1px outset;
}
tr:nth-child(1) > td:nth-child(2) {
  width: 80%;
}
td::after {
  content: '\200B'; /* Insert zero-width space */
}
table { border: 1px outset; }
td    { border: 1px inset;  }
tr:nth-child(1) { background: red;   }
tr:nth-child(2) { background: green; }
tr:nth-child(3) { background: blue;  }
<table>
  <tbody>
    <tr>
      <td></td>
      <td colspan="2"></td>
      <td></td>
    </tr>
    <tr>
      <td colspan="2"></td>
      <td colspan="2"></td>
    </tr>
    <tr>
      <td colspan="4"></td>
    </tr>
  </tbody>
</table>

关于html - 表格行的不同宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40830825/

相关文章:

css - 渐变圆 Angular 边框显示:block

html - 位置相对div内的绝对?

iphone - 如何在加载 URL 后将本地样式/JS 应用到 UIWebview

css - Bootstrap 4 中心和中间对齐表单元素

javascript - 通过jquery/javascript在span/tspan中设置多个空格

html - 使用 CSS 省略号在悬停时显示截断的文本与其下方的文本重叠

html - 如何在移动模式下拆分 Bootstrap 列

javascript - 仅使用 css 和 JS 的 css 悬停覆盖

javascript - 如何在 JSF 中将 toDataURL 方法返回的 Canvas 内容作为图像存储在磁盘上

html - 无论标签长度如何,始终将表格居中并排列输入