Acm*_*ion 5 css webkit google-chrome scrollbar
当通过选择器在 CSS 中使用自定义滚动条样式时::-webkit-scrollbar
,根据display
目标元素的属性,可以获取 asingle-button
或 a double-button
。
请参阅下面的示例,该示例显示了带有display: flex
和的元素的不同行为display: block
。
body
{
background: #111;
color: white;
}
.wrapper
{
height: 150px;
overflow-y: scroll;
background: #333;
display: flex;
padding: 10px;
}
.wrapper > div
{
height: 300px;
}
.custom-scrollbar::-webkit-scrollbar
{
width: 16px;
height: 16px;
}
.custom-scrollbar::-webkit-scrollbar-track-piece
{
background-color: #444;
}
.custom-scrollbar::-webkit-scrollbar-thumb
{
background: #555;
}
.custom-scrollbar::-webkit-scrollbar-button
{
background: #666;
}
.custom-scrollbar::-webkit-scrollbar-button:vertical:decrement,
.custom-scrollbar::-webkit-scrollbar-button:vertical:increment,
.custom-scrollbar::-webkit-scrollbar-button:horizontal:decrement,
.custom-scrollbar::-webkit-scrollbar-button:horizontal:increment
{
border: 1px solid #000;
}
.custom-scrollbar::-webkit-scrollbar-button:single-button:vertical:decrement,
.custom-scrollbar::-webkit-scrollbar-button:single-button:vertical:increment,
.custom-scrollbar::-webkit-scrollbar-button:single-button:horizontal:decrement,
.custom-scrollbar::-webkit-scrollbar-button:single-button:horizontal:increment
{
background: #AAA
}
Run Code Online (Sandbox Code Playgroud)
Device: Win10
<br />
Browser: Chrome
<br />
Goal: Custom styled scrollbar without the "double button", regardless of the display property.
<br />
<strong>Question</strong>: How to disable the "double button" completely?
<br />
<br />
<div style="display: flex">
<div style="width: 30%">
<div class="custom-scrollbar wrapper">
<div>
display: flex
<br />
scrollbar: custom
<br />
double-button: visible (= BAD)
</div>
</div>
</div>
<div style="width: 5%">
</div>
<div style="width: 30%">
<div class="custom-scrollbar wrapper" style="display: block">
<div>
display: block
<br />
scrollbar: custom
<br />
double-button: not visible (= GOOD)
</div>
</div>
</div>
</div>
<br />
<br />
<div style="display: flex">
<div style="width: 30%">
<div class="wrapper">
<div>
display: flex
<br />
scrollbar: default
<br />
double-button: not visible (= GOOD)
</div>
</div>
</div>
<div style="width: 5%">
</div>
<div style="width: 30%">
<div class="wrapper" style="display: block">
<div>
display: block
<br />
scrollbar: default
<br />
double-button: not visible (= GOOD)
</div>
</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
CodePen链接:https://codepen.io/Acmion/pen/VweKxZa
如何完全禁用double-button
?
要摆脱双按钮,请使用以下命令:
::-webkit-scrollbar-button:vertical:start:increment,
::-webkit-scrollbar-button:vertical:end:decrement,
::-webkit-scrollbar-button:horizontal:start:increment,
::-webkit-scrollbar-button:horizontal:end:decrement
{
display: none;
}
Run Code Online (Sandbox Code Playgroud)
请注意,在这种情况下,我们不需要触及其他四个类似的伪选择器:
::-webkit-scrollbar-button:vertical:start:decrement,
::-webkit-scrollbar-button:vertical:end:increment,
::-webkit-scrollbar-button:horizontal:start:decrement,
::-webkit-scrollbar-button:horizontal:end:increment
Run Code Online (Sandbox Code Playgroud)
因此,不要对包含这些内容的其他答案感到困惑。
归档时间: |
|
查看次数: |
2392 次 |
最近记录: |