【发布时间】:2016-06-14 18:23:59
【问题描述】:
我遇到了最奇怪的事情。我正在使用一个简单的 jquery 脚本来使 thead 在 tbody 滚动时保持原位。它工作得非常好,除了边界的一些奇怪行为。查看 Pen,您可以看到每个 th 底部的红色边框。我试过把它放在 thead 和 thead 的 tr 上,但它的行为总是一样的。它消失在……它自己的下面?我什至不确定。
http://codepen.io/sinrise/pen/NrxgWG
我正在使用引导程序和 SCSS。
我现在的解决方案是在 ths 中添加一个 :before,它只是一个 abs pos 框,是我想要的边框宽度的高度。它工作正常,但如果可能的话,我真的很想使用实际的边框。谢谢!
HTML
<div class="container">
<div class="table-fixedheader" style="height: 200px; overflow-y: auto;">
<table class="table table-striped">
<thead>
<tr>
<th>One</th>
<th>Two</th>
<th>Three</th>
</tr>
</thead>
<tbody>
<tr>
<td><input type="text" value="#1" /></td>
<td>Thing</td>
<td>This is a long desctiption of some thing.</td>
</tr>
<tr>
<td>#2</td>
<td>Thing</td>
<td>This is a long desctiption of some thing.</td>
</tr>
<tr>
<td>#3</td>
<td>Thing</td>
<td>This is a long desctiption of some thing.</td>
</tr>
<tr>
<td>#4</td>
<td>Thing</td>
<td>This is a long desctiption of some thing.</td>
</tr>
<tr>
<td>#5</td>
<td>Thing</td>
<td>This is a long desctiption of some thing.</td>
</tr>
<tr>
<td>#6</td>
<td>Thing</td>
<td>This is a long desctiption of some thing.</td>
</tr>
<tr>
<td>#7</td>
<td>Thing</td>
<td>This is a long desctiption of some thing.</td>
</tr>
<tr>
<td>#8</td>
<td>Thing</td>
<td>This is a long desctiption of some thing.</td>
</tr>
</tbody>
</table>
</div>
</div>
CSS
.container { padding: 30px; }
.table-fixedheader table thead tr th {
border-bottom: 5px solid red;
position: relative;
}
.table-fixedheader thead {
background-color: #cccccc;
}
JQ
$(".table-fixedheader").scroll(function() {
$(this).find("thead").css("transform", "translate(0," + this.scrollTop + "px)");
});
【问题讨论】:
-
您好,您希望红色边框保持不变?在 Firefox 中,我只能在顶部看到一个,并且它会滚动到视野之外。
-
是的,我的意思是,它位于 thead 单元格上,因此它应该与 thead 的其余部分及其后代保持一致......我不明白。
-
我看到了问题,它设置为保持不动但移动。让我再想一想。
标签: javascript html twitter-bootstrap css