我正在努力解决一个问题,如果我在父元素上将溢出属性设置为auto,则无法使用粘性位置。我尝试了很多方法,比如为sticky属性的元素添加一个额外的 Package 器,使用clip而不是auto,但这些都没有帮助。我找到了一个应用了一些js脚本的解决方案,但如果可能的话,我宁愿使用纯CSS。
<div className="wrapper">
<div className="left">
<div className="header" />
</div>
<div className="right">
<div className="header">Blablabla blablabla blabla</div>
<div className="table"/>
</div>
</div>
和css:
.wrapper {
margin-top: 30px;
display: grid;
grid-template-columns: 200px auto;
width: 100%;
max-height: 30vh;
overflow-y: auto;
position: relative;
}
.left {
background-color: chocolate;
}
.right {
background-color: chartreuse;
height: 50vh;
overflow-x: auto;
position: relative;
}
.header {
height: 20px;
width: 100%;
background-color: black;
position: sticky;
top: 0;
color: white;
}
.table {
width: 2000px;
}
我创建了一个小例子来玩:https://stackblitz.com/edit/react-starter-typescript-yrmmde
我想实现的是有正确的标题粘性,以及但正确的容器应在X轴上滚动在同一时间
1条答案
按热度按时间s71maibg1#
你把你的头放在右边的div里面。我把它从里面移走,并根据它们的优先级给它们z-index。希望这就是你正在寻找的解决方案。