Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
没有滚动的页面怎么会有一个元素粘在一个 div 的顶部overflow-y: scroll?
overflow-y: scroll
例子:
你可以看到有一个表的 div 有溢出-y:滚动。现在我想让表头粘在父 div 的顶部。这甚至可能吗?还要记住,div 也可能有溢出-x。
希望你能帮我!谢谢。
position: sticky; top: 0;
这将有助于将表头固定在溢出容器内。例如:
`<div class="table-container" style="overflow-y: scroll;"> <div class="table-header style="position: sticky; top: 0;"></div> <div class="table-body"></div> </div> `