我想修复表的标题。表格存在于可滚动的 div 中。下面是我的代码。
<div id="table-wrapper">
<div id="table-scroll">
<table bgcolor="white" border="0" cellpadding="0" cellspacing="0" id="header-fixed" width="100%" overflow="scroll" class="scrollTable">
<thead>
<tr>
<th>Order ID</th>
<th>Order Date</th>
<th>Status</th>
<th>Vol Number</th>
<th>Bonus Paid</th>
<th>Reason for no Bonus</th>
</tr>
</thead>
<tbody>
<tr>
<td><%=snd.getOrderId()%></td>
<td><%=snd.getDateCaptured()%></td>
<td><%=snd.getOrderStatus()%></td>
<td>Data Not Available</td>
<td>Data Not Available</td>
<td>Data Not Available</td>
</tr>
</tbody>
</table>
</div>
</div>
下面是我用于上述 div 的 CSS:
#table-wrapper {
position:relative;
}
#table-scroll {
height:250px;
overflow:auto;
margin-top:20px;
}
#table-wrapper table {
width:100%;
}
#table-wrapper table * {
background:white;
color:black;
}
#table-wrapper table thead th .text {
position:absolute;
top:-20px;
z-index:2;
height:20px;
width:35%;
border:1px solid red;
}
原文由 Rohan 发布,翻译遵循 CC BY-SA 4.0 许可协议
做这样的事情怎么样?我是从零开始做的…
我所做的是使用 2 个表,一个用于标题,它始终是静态的,另一个表呈现单元格,我使用
div
具有固定高度的元素包装,并启用滚动,我正在使用overflow-y: auto;
Also make sure you use
table-layout: fixed;
with fixed widthtd
elements so that yourtable
doesn’t break when a string withoutwhite space
is used , 所以为了打破我正在使用的字符串word-wrap: break-word;
演示