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代码>在父元素上。我认为这是工作,需要一些修改。谢谢你的关注是的,是的。如果问题还没有解决,我明天就解决。没问题!事实上,他大声笑着说:“已经很晚了,我喝醉了,所以我对此不太确定。”。