用rowspan修复了第一个表列
我正在使用一个简单的表模板来修复第一列。在许多用例中工作正常,但如果使用“ rowspan”。
HTML:
<table>
<tbody>
<tr>
<td class='first'>0</td>
<td>1</td>
<td>2</td>
<td>3</td>
</tr>
<tr>
<td class='first' rowspan='3'>0</td>
<td>1</td>
<td>2</td>
<td>3</td>
</tr>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
</tr>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
</tr>
<tr>
<td class='first'>0</td>
<td>1</td>
<td>2</td>
<td>3</td>
</tr>
</tbody>
</table>
CSS:
table td {
border: 1px solid red;
background: lightpink;
min-width: 100px;
max-width: 100px;
width: 100px;
height: 20px;
}
table td.first:nth-child(1) {
border: 1px solid blue;
background: lightblue;
position: relative;
display: block;
width: 300px;
min-width: 300px;
max-width: 300px;
}
table tbody {
position: relative;
display: block;
overflow: scroll;
width: 500px;
}
table {
position: relative;
overflow: hidden;
border: 1px solid black;
}
JS(jQuery):
$('tbody').scroll(function(e) {
$('td.first:nth-child(1)').css("left", $("tbody").scrollLeft());
});
我需要具有特定宽度的第一列。以及所有其他具有不同宽度的列。 不幸的是,如果使用“ rowspan”,并且每行的第一块TD都设置为“ Display:block”,则它不起作用。
I'm using a simple table template to be able to fix the first column. Working fine in many use cases but not in case the 'rowspan' is used.
HTML:
<table>
<tbody>
<tr>
<td class='first'>0</td>
<td>1</td>
<td>2</td>
<td>3</td>
</tr>
<tr>
<td class='first' rowspan='3'>0</td>
<td>1</td>
<td>2</td>
<td>3</td>
</tr>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
</tr>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
</tr>
<tr>
<td class='first'>0</td>
<td>1</td>
<td>2</td>
<td>3</td>
</tr>
</tbody>
</table>
CSS:
table td {
border: 1px solid red;
background: lightpink;
min-width: 100px;
max-width: 100px;
width: 100px;
height: 20px;
}
table td.first:nth-child(1) {
border: 1px solid blue;
background: lightblue;
position: relative;
display: block;
width: 300px;
min-width: 300px;
max-width: 300px;
}
table tbody {
position: relative;
display: block;
overflow: scroll;
width: 500px;
}
table {
position: relative;
overflow: hidden;
border: 1px solid black;
}
JS (jQuery):
$('tbody').scroll(function(e) {
$('td.first:nth-child(1)').css("left", $("tbody").scrollLeft());
});
I need to have the first column with a specific width. And all other columns with different width.
Unfortunately it is not working if the 'rowspan' is used and the first TD of each row is set to 'display: block'.
See my example: https://jsfiddle.net/zqjc9h0p/2/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以替换
显示:block
用显示:table-cell
:You can replace
display: block
withdisplay: table-cell
: