html - 具有可滚动主体和 colgroup 的表格不起作用

标签 html css

我想通过 colgroup 定义列的宽度。此外,tbody 应该是可滚动的。但这是行不通的。有没有不用js的解决方案?

js fiddle

HTML

     <colgroup>
      <col span="1" style="width: 15%;">
      <col span="1" style="width: 40%;">
      <col span="1" style="width: 20%;">
      <col span="1" style="width: 25%;">
    </colgroup>

最佳答案

添加到你的CSS:

td:nth-child(1), th:nth-child(1) {
  width: 15%;
}
td:nth-child(2), th:nth-child(2) {
  width: 40%;
}
td:nth-child(3), th:nth-child(3) {
  width: 20%;
}
td:nth-child(4), th:nth-child(4) {
  width: 25%;
}

tbody 滚动在 chrome 中工作正常。不知道其他浏览器怎么样

关于html - 具有可滚动主体和 colgroup 的表格不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40933403/

相关文章:

javascript - 如何跟踪菜单中的 css 类?

javascript - 在 javascript/jQuery 中动态更改元素的属性

javascript - 复制时不显示服务内容

javascript不想解析文本超过两次

javascript - 歌剧错误 : Uncaught exception: TypeError: Cannot convert 'xxxxxx' to object

jquery - idTab 不起作用

html - ionic : how to set same font in span tag for different resolutions?

html - 在 TABLE 固定的情况下是否可以保持 TD 的流动性?

html - 如何为所有相同的填充制作价格 block

html - 显示表和 .each block 的问题