【问题标题】:table with sticky header and horizontal scroll带有粘性标题和水平滚动的表格
【发布时间】:2022-01-19 22:48:47
【问题描述】:

我想要一个带有粘性标题和水平滚动的表格。

我不想在表格内垂直滚动。它应该随着页面滚动。所以没有设定桌子的高度。 这甚至可能吗?

这是不工作示例的代码笔: https://codepen.io/fwitkowski/pen/zYEQvvg

当我从表容器中删除溢出:自动时,位置粘性工作得很好。

.table-container {
  max-width:350px;
  overflow-x:auto; /* for horizontal scroll */
  position: relative; /* relative to the normal flow */
  border: solid 5px red /* for reference */
}

【问题讨论】:

    标签: html css html-table sticky


    【解决方案1】:

    根据the MDN documentation

    一个粘性元素“粘”到它最近的具有“滚动机制”的祖先(当 overflowhiddenscrollautooverlay 时创建),即使该祖先不是'不是最近的实际滚动祖先。

    an active GitHub issue discussing this on the W3C repo,它自 2017 年以来一直在运行。提出了各种解决方法,但它们似乎都依赖于向表格/表格容器添加固定高度,或 using Javascript as in this answer

    至少目前,这不是本机支持的。

    【讨论】:

    • 我认为这是正确的(不幸的是)我将使用最大高度并为两个表格容器(X 和 Y)设置滚动条
    猜你喜欢
    • 1970-01-01
    • 2018-09-21
    • 2020-04-11
    • 2020-09-28
    • 1970-01-01
    • 2016-10-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多