我有一个有很多行的表格,我想在滚动时覆盖一个固定的表格标题。页面的布局是响应式的,带有一个固定的左侧菜单,可以有 2 个固定宽度中的 1 个。我在将固定标题中的列与表格对齐时遇到问题。
按照这个小提琴
body {
width: 1519px;
}
#fixedheader {
width: calc (100% - 100px);
}
#contenttable {
width: 100%;
}
#fixedheader {
width: calc(100% - 100px);
position: fixed;
top: 300px;
border: 1px solid black;
background-color: yellow;
}
.donor_name_header {
width: calc((100% - 100px)/5);
}
.total_row_header,
.total_variance_header {
width: calc((100% - 100px)/10);
}
.bar0 {
background-color: #CCFFCC;
}
<body>
<table>
<tbody>
<tr>
<td style="100px">Left column, width may change between 2 values</td>
<td style="position: relative;">
<table id="fixedheader">
<thead>
<tr>
<th style="width:20%;">
<!--placehold header row in data block-->
</th>
<th style="width: 5.8333333333333%">
Jan 17 </th>
<th style="width: 5.8333333333333%">
Feb 17 </th>
<th style="width: 5.8333333333333%">
Mar 17 </th>
<th style="width: 5.8333333333333%">
Apr 17 </th>
<th style="width: 5.8333333333333%">
May 17 </th>
<th style="width: 5.8333333333333%">
Jun 17 </th>
<th style="width: 5.8333333333333%">
Jul 17 </th>
<th style="width: 5.8333333333333%">
Aug 17 </th>
<th style="width: 5.8333333333333%">
Sep 17 </th>
<th style="width: 5.8333333333333%">
Oct 17 </th>
<th style="width: 5.8333333333333%">
Nov 17 </th>
<th style="width: 5.8333333333333%">
Dec 17 </th>
<th style="width:10%;">
Total
<!--placehold header row in data block-->
</th>
<th style="width:10%;">
<!--placehold header row in data block-->
</th>
</tr>
</thead>
</table>
<table id="contenttable">
<thead>
<tr>
<th style="width:20%;">
<!--placehold header row in data block-->
</th>
<th style="width: 5.8333333333333%">
Jan 17 </th>
<th style="width: 5.8333333333333%">
Feb 17 </th>
<th style="width: 5.8333333333333%">
Mar 17 </th>
<th style="width: 5.8333333333333%">
Apr 17 </th>
<th style="width: 5.8333333333333%">
May 17 </th>
<th style="width: 5.8333333333333%">
Jun 17 </th>
<th style="width: 5.8333333333333%">
Jul 17 </th>
<th style="width: 5.8333333333333%">
Aug 17 </th>
<th style="width: 5.8333333333333%">
Sep 17 </th>
<th style="width: 5.8333333333333%">
Oct 17 </th>
<th style="width: 5.8333333333333%">
Nov 17 </th>
<th style="width: 5.8333333333333%">
Dec 17 </th>
<th style="width:10%;">
Total&n
<table id="fixedheader" style="display: none;">
<thead>
<tr>
<th style="width:20%;">
<!--placehold header row in data block-->
</th>
<th style="width: 5.8333333333333%">
Jan 17 </th>
<th style="width: 5.8333333333333%">
Feb 17 </th>
<th style="width: 5.8333333333333%">
Mar 17 </th>
<th style="width: 5.8333333333333%">
Apr 17 </th>
<th style="width: 5.8333333333333%">
May 17 </th>
<th style="width: 5.8333333333333%">
Jun 17 </th>
<th style="width: 5.8333333333333%">
Jul 17 </th>
<th style="width: 5.8333333333333%">
Aug 17 </th>
<th style="width: 5.8333333333333%">
Sep 17 </th>
<th style="width: 5.8333333333333%">
Oct 17 </th>
<th style="width: 5.8333333333333%">
Nov 17 </th>
<th style="width: 5.8333333333333%">
Dec 17 </th>
<th style="width:10%;">
Total
<!--placehold header row in data block-->
</th>
<th style="width:10%;">
<!--placehold header row in data block-->
</th>
</tr>
</thead>
</table>bsp;
<!--placehold header row in data block-->
</th>
<th style="width:10%;">
<!--placehold header row in data block-->
</th>
</tr>
</thead>
<tbody>
<tr class="each_donor">
<td class="donor_name none" rowspan="2" style="width: 20%;">
<p> First Last</p>
<p>First & Other Last</p>
</td>
<td class="detail_month" style="width: 5.8333333333333%">
<span class="variance"><sup> </sup></span>
</td>
<td class="detail_month" style="width: 5.8333333333333%">
<span class="variance"><sup> </sup></span>
</td>
<td class="detail_month" style="width: 5.8333333333333%">
<span class="variance"><sup> </sup></span>
</td>
<td class="detail_month" style="width: 5.8333333333333%">
<span class="variance"><sup> </sup></span>
</td>
<td class="detail_month" style="width: 5.8333333333333%">
<span class="variance"><sup> </sup></span>
</td>
<td class="detail_month" style="width: 5.8333333333333%">
<span class="variance"><sup> </sup></span>
</td>
<td class="detail_month" style="width: 5.8333333333333%">
<span class="variance"><sup> </sup></span>
</td>
<td class="detail_month" style="width: 5.8333333333333%">
<span class="variance"><sup> </sup></span>
</td>
<td class="detail_month" style="width: 5.8333333333333%">
<span class="variance"><sup> </sup></span>
</td>
<td class="detail_month" style="width: 5.8333333333333%">
<span class="variance"><sup> </sup></span>
</td>
<td class="detail_month" style="width: 5.8333333333333%">
<span class="variance"><sup> </sup></span>
</td>
<td class="detail_month" style="width: 5.8333333333333%">
<span class="variance"><sup> </sup></span>
</td>
<td class="total_row" rowspan="2">
$360.00 </td>
<td class="total_variance" rowspan="2">
</td>
</tr>
<tr>
<td class="recurring_period colspan bar0" colspan="12">
$30.00 monthly </td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<script>
// tell the embed parent frame the height of the content
if (window.parent && window.parent.parent) {
window.parent.parent.postMessage(["resultsFrame", {
height: document.body.getBoundingClientRect().height,
slug: "None"
}], "*")
}
</script>
</body>
我找不到正确计算第一列和最后两列百分比的方法。我努力了:
- 宽度:计算(20% - 20px);
- 宽度:20%;
- 宽度:计算(100%-100px)/5;(这对我来说似乎是正确的,并且在片段中)
不幸的是我也不能移动位置:相对于顶部