具有隐藏溢出(滚动)的弹性布局中的绝对定位按钮
Absolute positioned button in a flex layout with hidden overflow (with scolling)
我正在尝试实现一个 Flex-layout
我已经实现的隐藏滚动条。但现在我还需要一个 absolute/fixed 按钮,但我没能让它工作。
没有隐藏的滚动条它工作:
但是当我隐藏滚动条时,按钮会粘在顶部,这是不受欢迎的。
<style>
.root {
background-color: #fff;
display: flex;
height:100%;
}
.pane {
flex-grow: 1;
flex-shrink: 1;
display: flex;
overflow-x: hidden;
overflow-y: visible;
-ms-overflow-style: none;
height: 100%;
width: 400px;
}
.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
<br/> Lorem ipsum dolor sit amet, etc etc
<br/> Lorem ipsum dolor sit amet, etc etc
<br/> Lorem ipsum dolor sit amet, etc etc
<br/> The button should stick to the right of the text and scroll width the text;
</div>
</div>
</div>
问题很简单,绝对定位元素与滚动元素无关。
给它 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>
我正在尝试实现一个 Flex-layout
我已经实现的隐藏滚动条。但现在我还需要一个 absolute/fixed 按钮,但我没能让它工作。
没有隐藏的滚动条它工作:
但是当我隐藏滚动条时,按钮会粘在顶部,这是不受欢迎的。
<style>
.root {
background-color: #fff;
display: flex;
height:100%;
}
.pane {
flex-grow: 1;
flex-shrink: 1;
display: flex;
overflow-x: hidden;
overflow-y: visible;
-ms-overflow-style: none;
height: 100%;
width: 400px;
}
.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
<br/> Lorem ipsum dolor sit amet, etc etc
<br/> Lorem ipsum dolor sit amet, etc etc
<br/> Lorem ipsum dolor sit amet, etc etc
<br/> The button should stick to the right of the text and scroll width the text;
</div>
</div>
</div>
问题很简单,绝对定位元素与滚动元素无关。
给它 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>