Chrome: 应用两个滚动条时的自定义滚动条问题
Chrome: custom scrollbar problem when both scroll bars are applied
检查 Chrome/Safari/new Edge 中的以下代码段,并将容器滚动到最底部:
body { background-color: #fff }
section {
background-color: #f8f8f8;
width: 400px;
height: 150px;
padding: 10px;
overflow: overlay;
}
.force-overflow {
background-image: linear-gradient(45deg, orange, yellow, orange);
height: 600px;
}
::-webkit-scrollbar {
background-color: #F5F5F5;
height: 10px;
width: 10px;
}
::-webkit-scrollbar-track {
background-color: #F5F5F5;
box-shadow: inset 0 0 3px rgba(0,0,0,0.2);
}
::-webkit-scrollbar-thumb {
background: #999;
}
::-webkit-scrollbar-thumb:hover {
background: #444;
}
::-webkit-scrollbar-corner {
background: transparent;
}
<section>
<div class="force-overflow"></div>
</section>
这按预期工作。
现在如果我们添加一个水平溢出:
body { background-color: #fff }
section {
background-color: #f8f8f8;
width: 400px;
height: 150px;
padding: 10px;
overflow: overlay;
}
.force-overflow {
background-image: linear-gradient(45deg, orange, yellow, orange);
height: 600px;
width: 1200px;
}
::-webkit-scrollbar {
background-color: #F5F5F5;
height: 10px;
width: 10px;
}
::-webkit-scrollbar-track {
background-color: #F5F5F5;
box-shadow: inset 0 0 3px rgba(0,0,0,0.2);
}
::-webkit-scrollbar-thumb {
background: #999;
}
::-webkit-scrollbar-thumb:hover {
background: #444;
}
::-webkit-scrollbar-corner {
background: transparent;
}
<section>
<div class="force-overflow"></div>
</section>
然后滚动到 right/bottom,我们得到这个:
我知道我可以使用 overflow: auto;
而不是 overflow: overlay;
来解决这个问题,但我真的很想坚持使用 overlay
,因为它会阻止您的布局尽快“跳跃”滚动条显示 up/vanishes.
有人知道如何解决这个问题吗?
一个 hacky 解决方案是添加一些 box-shadow 来覆盖这部分:
::-webkit-scrollbar-thumb:horizontal {
box-shadow: 3px 0 0 0;
}
::-webkit-scrollbar-thumb:vertical {
box-shadow: 0 3px 0 0;
}
body { background-color: #fff }
section {
background-color: #f8f8f8;
width: 400px;
height: 200px;
padding: 10px;
overflow: overlay;
}
.force-overflow {
background-image: linear-gradient(45deg, orange, yellow, orange);
height: 800px;
width: 1200px;
}
::-webkit-scrollbar {
background-color: #F5F5F5;
height: 10px;
width: 10px;
}
::-webkit-scrollbar-track {
background-color: #F5F5F5;
box-shadow: inset 0 0 3px rgba(0,0,0,0.2);
}
::-webkit-scrollbar-thumb {
background: #999;
color:#999;
transition-duration: 2s;
}
::-webkit-scrollbar-thumb:horizontal {
box-shadow: 3px 0 0 0;
}
::-webkit-scrollbar-thumb:vertical {
box-shadow: 0 3px 0 0;
}
::-webkit-scrollbar-thumb:hover {
background: #444;
color:#444;
transition-duration: 2s;
}
::-webkit-scrollbar-corner {
background: transparent;
}
<section>
<div class="force-overflow"></div>
</section>
检查 Chrome/Safari/new Edge 中的以下代码段,并将容器滚动到最底部:
body { background-color: #fff }
section {
background-color: #f8f8f8;
width: 400px;
height: 150px;
padding: 10px;
overflow: overlay;
}
.force-overflow {
background-image: linear-gradient(45deg, orange, yellow, orange);
height: 600px;
}
::-webkit-scrollbar {
background-color: #F5F5F5;
height: 10px;
width: 10px;
}
::-webkit-scrollbar-track {
background-color: #F5F5F5;
box-shadow: inset 0 0 3px rgba(0,0,0,0.2);
}
::-webkit-scrollbar-thumb {
background: #999;
}
::-webkit-scrollbar-thumb:hover {
background: #444;
}
::-webkit-scrollbar-corner {
background: transparent;
}
<section>
<div class="force-overflow"></div>
</section>
这按预期工作。
现在如果我们添加一个水平溢出:
body { background-color: #fff }
section {
background-color: #f8f8f8;
width: 400px;
height: 150px;
padding: 10px;
overflow: overlay;
}
.force-overflow {
background-image: linear-gradient(45deg, orange, yellow, orange);
height: 600px;
width: 1200px;
}
::-webkit-scrollbar {
background-color: #F5F5F5;
height: 10px;
width: 10px;
}
::-webkit-scrollbar-track {
background-color: #F5F5F5;
box-shadow: inset 0 0 3px rgba(0,0,0,0.2);
}
::-webkit-scrollbar-thumb {
background: #999;
}
::-webkit-scrollbar-thumb:hover {
background: #444;
}
::-webkit-scrollbar-corner {
background: transparent;
}
<section>
<div class="force-overflow"></div>
</section>
然后滚动到 right/bottom,我们得到这个:
我知道我可以使用 overflow: auto;
而不是 overflow: overlay;
来解决这个问题,但我真的很想坚持使用 overlay
,因为它会阻止您的布局尽快“跳跃”滚动条显示 up/vanishes.
有人知道如何解决这个问题吗?
一个 hacky 解决方案是添加一些 box-shadow 来覆盖这部分:
::-webkit-scrollbar-thumb:horizontal {
box-shadow: 3px 0 0 0;
}
::-webkit-scrollbar-thumb:vertical {
box-shadow: 0 3px 0 0;
}
body { background-color: #fff }
section {
background-color: #f8f8f8;
width: 400px;
height: 200px;
padding: 10px;
overflow: overlay;
}
.force-overflow {
background-image: linear-gradient(45deg, orange, yellow, orange);
height: 800px;
width: 1200px;
}
::-webkit-scrollbar {
background-color: #F5F5F5;
height: 10px;
width: 10px;
}
::-webkit-scrollbar-track {
background-color: #F5F5F5;
box-shadow: inset 0 0 3px rgba(0,0,0,0.2);
}
::-webkit-scrollbar-thumb {
background: #999;
color:#999;
transition-duration: 2s;
}
::-webkit-scrollbar-thumb:horizontal {
box-shadow: 3px 0 0 0;
}
::-webkit-scrollbar-thumb:vertical {
box-shadow: 0 3px 0 0;
}
::-webkit-scrollbar-thumb:hover {
background: #444;
color:#444;
transition-duration: 2s;
}
::-webkit-scrollbar-corner {
background: transparent;
}
<section>
<div class="force-overflow"></div>
</section>