问题很简单,绝对定位元素与滚动元素无关。
给它
position: relative
它会的。
堆栈片段
<style>
html, body {
overflow: hidden;
height: 100%;
}
.root {
background-color: #fff;
display: flex;
height: 100%;
}
.pane {
position: relative; /* added */
flex-grow: 1;
flex-shrink: 1;
display: flex;
overflow-x: hidden;
overflow-y: visible;
-ms-overflow-style: none;
height: 100%;
}
.pane::-webkit-scrollbar {
display: none
}
div.pos {
position: absolute;
right: 0px;
width: 32px;
height: 32px;
background-color: #01689B;
color: #fff;
}
</style>
<div class="root">
<div class="pane">
<div class="pos">x</div>
<div style="height: 2000px">
Lorem ipsum dolor sit amet, etc etc
</div>
</div>
</div>