我试图展示一个显示分组数据的 table
。
表头应该固定在窗口视图的顶部,还有一些包含组标题的表行。
为了简单起见,我在Codepen上创建了以下示例: https://codepen.io/andreivictor/pen/RwZRZav
我尝试过的代码如下:
td.sticky {
background: red;
color: white;
position: sticky;
top: 50px; // this is the header height
}
这在Chrome和Firefox上效果良好。
问题是它在Safari(测试版本为v14)中不起作用,也不适用于Safari移动端。请见截图:https://i.imgur.com/8NEgPYB.png - 悬停行的位置固定,但top
位置与表格顶部不同(而不是视口顶部)。
top: 0
而不是top: 50px
,它是否适用于Safari? - Bercisafari
使用top: 0
,其他浏览器使用top: 50px
。但这似乎是某种hack方法,我也在尝试理解为什么safari
会出现这种情况。 - andreivictor