php - 如何在桌子上有粘性的头饰
问题描述
我希望thead 在表格中滚动时不要移动,我无法在 tbody 上设置溢出自动,所以我该如何解决?
我已经尝试过 style="overflow: auto; height: 650px;" 在 tbody 上,但它甚至根本不起作用
<div class="row m-t-30">
<div style="overflow: auto; height: 650px;" class="col-md-12">
<div class="table-responsive m-b-40">
<table id="productsTable" class="table table-borderless table-data3">
<thead>
<tr>
<th>Klant</th>
<th>Werknemer</th>
<th>Datum</th>
<th></th>
</tr>
</thead>
<tbody>
<?php
foreach ($clients->getAllclients() as $client) {
echo '<tr>';
echo '<td>' . $client['client_name'] . '</td>';
echo '<td>' . $client['client_id'] . '</td>';
echo '<td>' . $client['client_address'] . '</td>';
echo '<td><button class="item" data-toggle="tooltip" data-placement="top" title="See" onclick="seeOrder(\'' . $client['client_id'] . '\')"><i style="font-size: 20px" class="zmdi zmdi-search"></i></button></td>';
echo '</tr>';
}
?>
</tbody>
</table>
</div>
</div>
</div>
解决方案
您可以position: sticky;
用于表
table thead tr th {
background-color: white;
position: sticky;
top: -1px;
}
下面是sticky thead的演示
table thead tr th {
background-color: white;
position: sticky;
top: -1px;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<table class="table">
<thead>
<tr>
<th>column1</th>
<th>column2</th>
<th>column3</th>
<th>column4</th>
</tr>
</thead>
<tbody>
<tr>
<td>td</td>
<td>td</td>
<td>td</td>
<td>td</td>
</tr>
<tr>
<td>td</td>
<td>td</td>
<td>td</td>
<td>td</td>
</tr>
<tr>
<td>td</td>
<td>td</td>
<td>td</td>
<td>td</td>
</tr>
<tr>
<td>td</td>
<td>td</td>
<td>td</td>
<td>td</td>
</tr>
<tr>
<td>td</td>
<td>td</td>
<td>td</td>
<td>td</td>
</tr>
<tr>
<td>td</td>
<td>td</td>
<td>td</td>
<td>td</td>
</tr>
<tr>
<td>td</td>
<td>td</td>
<td>td</td>
<td>td</td>
</tr>
<tr>
<td>td</td>
<td>td</td>
<td>td</td>
<td>td</td>
</tr>
<tr>
<td>td</td>
<td>td</td>
<td>td</td>
<td>td</td>
</tr>
<tr>
<td>td</td>
<td>td</td>
<td>td</td>
<td>td</td>
</tr>
<tr>
<td>td</td>
<td>td</td>
<td>td</td>
<td>td</td>
</tr>
<tr>
<td>td</td>
<td>td</td>
<td>td</td>
<td>td</td>
</tr>
<tr>
<td>td</td>
<td>td</td>
<td>td</td>
<td>td</td>
</tr>
<tr>
<td>td</td>
<td>td</td>
<td>td</td>
<td>td</td>
</tr>
</tbody>
</table>
推荐阅读
- javascript - 如何从另一个组件单击按钮时更新一个类组件中的状态?
- android - 函数从不用于 LifecycleObserver 中使用 OnLifecycleEvent 注释的方法
- mysql - 我在mysql中过滤日期时间有问题
- bash - 外壳内的heredoc有问题。bash 脚本
- java - 铸件供应商
给供应商 爪哇 - r - 如何找到投资组合中每只股票的月收益
- c# - 如何避免 Linq 中过滤器 API 中的 if else 语句
- html - 透明导航栏 - 不显示背景
- android - 境界+魔石| @JsonClass 不能应用于 [class],RealmObject 不是 Kotlin 类型public
- c++ - 检查(可能的)中文字符串中的无效字符