在屏幕底部显示水平滚动条,而不是在元素底部



我有一个内容很长的网站,所以网站必须是垂直滚动的。然而,在页面底部也有一个水平滚动的div。不幸的是,这个元素的水平滚动条在用户向下滚动之前是不可见的。有没有办法显示水平滚动条总是在屏幕底部?下面是一个例子。

.container {
overflow-y: auto;
overflow-x: hidden;
}
.content {
background-color: lightblue;
height: 5rem;
}
.scrollable-content {
background-color: lightgreen;
height: 100vh;
overflow-x: auto;
width: 100%;
}
.wide-content {
width: 150vw;
}
<div class="container">
<div class="content">
Div which is not horizontally scrollable
</div>
<div class="scrollable-content">
Div which is horizontally scrollable
<div class="wide-content">
Some wide content
</div>
</div>
</div>

您必须在css中添加一些-webkit-scrollbar选择器,以便每次都显示滚动条。看看下面的例子:

.scrollable-content::-webkit-scrollbar {
-webkit-appearance: none;
}
.scrollable-content::-webkit-scrollbar:horizontal {
height: 11px;
}
.scrollable-content::-webkit-scrollbar-thumb {
border-radius: 8px;
border: 2px solid white;
background-color: rgba(0, 0, 0, .5);
}
.scrollable-content::-webkit-scrollbar-track { 
background-color: #fff; 
border-radius: 8px; 
} 
.container {
overflow-y: auto;
overflow-x: hidden;
}
.content {
background-color: lightblue;
height: 5rem;
}
.scrollable-content {
background-color: lightgreen;
height: 30vh;
overflow-x: auto;
width: 100%;
}
.wide-content {
width: 150vw;
}
<div class="container">
<div class="content">
Div which is not horizontally scrollable
</div>
<div class="scrollable-content" style="width:500px; overflow-x:scroll; border:dotted 1px; white-space: nowrap;padding-bottom:10px;">
	Div which is horizontally scrollable
<div class="wide-content">
Some wide content
</div>
</div>
</div>

我希望解决方案是如你所想象的

我将scrollable-content更改为:

.scrollable-content {
background-color: lightgreen;
height: 89vh;
width: 1000%;
}

和正文:

body {
overflow: hidden;
}

我希望这能帮助

最新更新