html - 如何使表格可滚动并具有固定高度
问题描述
我想在我的网站上有一个固定大小并允许滚动的表格。现在表格占据了整个页面,因为它有很多行数据。我想限制高度并使表格可滚动,这样它就不会占据整个页面。这是我的表格代码。我试图将表格包装在一个 div 中并设置 overflow: auto 但这似乎不起作用。
<table class="table table-dark">
<thead class="thead-light">
<tr>
<th>State</th>
<th>County</th>
<th>Total cases reported</th>
<th>Changes since last day</th>
</tr>
</thead>
<tr th:each="locationStat : ${locationStats}">
<td th:text="${locationStat.state}"></td>
<td th:text="${locationStat.country}"></td>
<td th:text="${locationStat.latestTotalCases}">0</td>
<td th:text="${locationStat.dailyChange}">0</td>
</tr>
</table>
解决方案
设置表格高度固定。像300px左右的东西。它制作了一个虚拟滚动条
推荐阅读
- c++ - 为什么函数 exp() 在 for 循环中调用时首先运行得这么慢?
- javascript - 每个表格单元格的数组输出
- python - 用 python 签署请求到币安未来
- dynamics-crm - Dynamics 365 CE 中“电话呼叫”活动的“呼叫”字段中的机会
- python - 如何在 Keras 的每次迭代中可视化训练准确性?
- ios - UITextView 未在键盘中显示地球图标
- javascript - if/else 语句在 return 语句内的循环内?
- angular - 数据未显示 Angular8(Metronic 主题)
- laravel - 如何在laravel中使用路由名称传递查询参数?
- c++ - 指向 64 位数字的 32 位是否安全?