Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/362.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何使表的第一列和第二列保持粘性_Javascript_Jquery_Css_Css Tables_Sticky - Fatal编程技术网

Javascript 如何使表的第一列和第二列保持粘性

Javascript 如何使表的第一列和第二列保持粘性,javascript,jquery,css,css-tables,sticky,Javascript,Jquery,Css,Css Tables,Sticky,我有一个属性为的div <div id="_body_container" style="height: 500px; overflow-x: auto; overflow-y: auto; "> </div>` ` 在这个div中,我有表,它有class视图表,此表有100%的宽度,这使得它的父div:\u body\u container可滚动。我想在\u body\u container发生左右滚动事件时,将此表的第一列和第二列固定在其位置上 结构类似于:假设

我有一个属性为的
div

<div id="_body_container" style="height: 500px; overflow-x: auto; overflow-y: auto; ">
</div>`

`
在这个div中,我有
,它有class
视图表
,此表有100%的宽度,这使得它的父div:
\u body\u container
可滚动。我想在
\u body\u container发生左右滚动事件时,将此表的第一列和第二列固定在其位置上


结构类似于:

假设每个部分都是一个
元素

CSS

table {
    position: relative;
    padding-left: (width-of-your-td-elements);
}
table td:first-of-type {
    position: absolute;
    left: 0;
}

试试看。时间不早了,我喝醉了,所以我对这件事不太确定。哦,请记住这是在使用CSS3,这在中不受支持。
位置:绝对
几乎正确。但您不必设置
左:0
。使用
left:auto
,您也可以备用
位置:relative

table {
    padding-left: (width-of-your-td-elements);
}

table td:first-of-type {
    position: absolute;
}

我已经试过这个了。如果第一列的绝对位置不再位于可滚动窗口内,则整个页面直到其高度都可见。这就是为什么要设置
position:relative在父元素上。我认为这是工作,需要一些修改。谢谢你的关注是的,是的。如果问题还没有解决,我明天就解决。没问题!事实上,他大声笑着说:“已经很晚了,我喝醉了,所以我对此不太确定。”。