html - 我怎样才能使我的 td 和 th 具有相同的宽度 - 包括仅放在 tbody 上的滚动条?
问题描述
我需要有可滚动的 tbody。出于这个原因,我放了两张桌子,一张用于thead,一张用于tbody。
但我找不到让这两个表具有相同宽度的方法。
我知道有很多解决方案可以用一张桌子制作这些,但它们都不能正常工作 - 因为我需要有 bakground - 颜色 - 其他解决方案的宽度直到右边的滚动条和那个不是我想要的
<table>
<thead>
<tr>
<th class="red">
Header 1
</th>
<th class="red">
Header 2
</th>
<th class="red">
Header 3
</th>
<th class="red">
Header 4
</th>
<th class="red">
Header 5
</th>
</tr>
</thead>
</table>
<table>
<tbody>
<tr>
<td class="red">Content 1</td>
<td class="red">Content 2</td>
<td class="red">Content 3</td>
<td class="red">Content 4</td>
<td class="red">Content 5</td>
</tr>
<tr>
<td class="red">Content 1</td>
<td class="red">Content 2</td>
<td class="red">Content 3</td>
<td class="red">Content 4</td>
<td class="red">Content 5</td>
</tr>
<tr>
<td class="red">Content 1</td>
<td class="red">Content 2</td>
<td class="red">Content 3</td>
<td class="red">Content 4</td>
<td class="red">Content 5</td>
</tr>
<tr>
<td class="red">Content 1</td>
<td class="red">Content 2</td>
<td class="red">Content 3</td>
<td class="red">Content 4</td>
<td class="red">Content 5</td>
</tr>
<tr>
<td class="red">Content 1</td>
<td class="red">Content 2</td>
<td class="red">Content 3</td>
<td class="red">Content 4</td>
<td class="red">Content 5</td>
</tr>
</tbody>
</table>
tbody {
display: block;
height: 50px;
overflow-y: scroll;
}
table {
border:1px solid red;
}
.red {
border:1px solid red;
}
解决方案
推荐阅读
- sql - 如何进行 Sequilize 查询以获取与年份无关的日期范围内的项目?
- javascript - 如何使编辑按钮从模式中工作?
- python - 如何向 Pandas 中的现有列添加值?
- react-native - React Native Webview:不支持浏览器
- ruby-on-rails - 如何在 Rails 6 中使用 Webpacker 跨多个客户端 JavaScript 文件共享变量和函数?
- javascript - 呼叫说无法读取属性'然后未定义(看起来有效)
- visual-studio-code - 插件如何获取宿主vscode的当前版本号?
- node.js - fetch() 对 Express 的 POST 请求生成空正文 {}
- python - 在 Python 中将浮动千位 5s 向上舍入
- jquery - 如何使用 jQuery 强制函数以特定顺序执行?