gpt4 book ai didi

html - 卡住 HTML 表格列的宽度

转载 作者:太空宇宙 更新时间:2023-11-03 18:55:41 25 4
gpt4 key购买 nike

我正在尝试制作一个包含固定列的表格,我正在关注这个例子:

http://jsfiddle.net/emn13/YMvk9/

容器:

 div { 
width: 600px;
overflow-x:scroll;
margin-left:5em;
overflow-y:visible;
padding-bottom:1px;
}

固定列:

.headcol {
position:absolute;
width:5em;
left:0;
top:auto;
border-right: 0px none black;
border-top-width:3px; /*only relevant for first row*/
margin-top:-3px; /*compensate for top border*/
}

问题是如果容器有一个固定的高度,比如说 100px,固定的列会保持它的默认高度而不会附加到滚动条上。

最佳答案

尝试添加一个额外的容器,您可以将其设置为相对定位。

div#container{
position:relative;
height:100px;
overflow:scroll;
}

您可以在下面的示例中看到固定行与其余行一起垂直滚动。

http://jsfiddle.net/VRNsX/

如果您不反对一点点 jQuery,这是我想出的另一种方法:

$('#tbl').scroll(function(e) {
var self = this;
$('.headcol').each(function() {
$(this).css({
'top': ($(this).index('.headcol') * $(this).outerHeight() + 3) - $(self).scrollTop()
});
});
});

http://jsfiddle.net/YMvk9/786/

关于html - 卡住 HTML 表格列的宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13532887/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com