将鼠标悬停在其上时如何更改-webkit-scrollbar宽度

All*_*len 5 css webkit google-chrome scrollbar

我想将滚动条的宽度更改为更宽,因此当用户将鼠标悬停在其上时,它看起来很清晰。

所以我写道:

::-webkit-scrollbar {
width: 7px;
height: 7px;
background-color: #ddd;
}
::-webkit-scrollbar:hover {
width: 10px;
height: 10px;
background-color: red;
}
Run Code Online (Sandbox Code Playgroud)

背景颜色更改为红色,但宽度未更改,是否有解决方法?这是plnkr

小智 17

border您可以通过使用而不是来实现这一点width

::-webkit-scrollbar {
    width: 7px;
    height: 7px;
}

::-webkit-scrollbar-thumb {
    background: #ababab;
    border-radius: 10px;
    border: 2px solid transparent;
    background-clip: padding-box; // <== make the border work
}

::-webkit-scrollbar-thumb:hover{
    border: 0;
}

::-webkit-scrollbar-track {
    background: transparent;
}
Run Code Online (Sandbox Code Playgroud)


Fre*_*ond 10

*:hover::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}
Run Code Online (Sandbox Code Playgroud)

这将改变任何元素滚动条的宽度和高度。如果您想更具体,只需将“*”替换为您选择的选择器。例如,要将其应用于具有“my-custom-scrollbar”类的元素的滚动条:

.my-custom-scrollbar:hover::-webkit-scrollbar {
        width: 10px;
        height: 10px;
}
Run Code Online (Sandbox Code Playgroud)

  • 当鼠标放在 div 上并滚动时,此功能有效。我正在寻找的是当鼠标放在 div 上时不放大,而仅在滚动条上放大。 (8认同)
  • 它将改变容器的宽度和高度。 (2认同)