在 Google Chrome 中使用 css 设置滚动条样式(-webkit)

问题描述 投票:0回答:4

有人可以帮帮我吗?我想为滚动条做一个简单的样式。在网上找了一些资料试了一下,但是好像因为某些原因真的不行。刷新页面时滚动条看起来很好,但是一旦你触摸滚动条它就会变得疯狂。它充满了很多颜色,你无法理解那是一个滚动条。

这里是你触摸它之前的样子 - http://i40.tinypic.com/a2evro.png

这是你触摸后的样子 - http://i44.tinypic.com/qzkirn.png

这是我放入 css 的代码:

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

::-webkit-scrollbar-thumb {
background-color: rgba(0, 0, 0, 0.2);
-webkit-box-shadow: inset 1px 1px 0 rgba(0,0,0,0.10),inset 0 -1px 0 rgba(0,0,0,0.07); }

谢谢大家。干杯。亚历克斯

css google-chrome webkit scrollbar
4个回答
88
投票

这是一个有效的例子

::-webkit-scrollbar {
    height: 12px;
    width: 12px;
    background: #000;
}

::-webkit-scrollbar-thumb {
    background: #393812;
    -webkit-border-radius: 1ex;
    -webkit-box-shadow: 0px 1px 2px rgba(0, 0, 0, 0.75);
}

::-webkit-scrollbar-corner {
    background: #000;
}

或者你可以使用 jScrollPane.


5
投票
.invisible-scrollbar {
  scrollbar-width: none;
}
.invisible-scrollbar::-webkit-scrollbar {
  display: none;
}

2
投票

对于 2021 年 12 月之后检查此答案的任何人,我添加了带有@orel 答案的片段(更新了代码,还添加了一些 html 并将滚动条样式从

background: #000;
更改为
background: #aaa;
为了更好地发现卷轴)。

::-webkit-scrollbar {
    height: 12px;
    width: 12px;
    background: #aaa;
}

::-webkit-scrollbar-thumb {
    background: #393812;
    -webkit-border-radius: 1ex;
    -webkit-box-shadow: 0px 1px 2px rgba(0, 0, 0, 0.75);
}

::-webkit-scrollbar-corner {
    background: #000;
}

.scrollable {
  max-width: 200px;
  max-height: 100%;
  
  height: 450px;
  /* change ` overflow: scroll ` to ` overflow: auto ` if you only want vertical scroll */
  overflow: scroll;
 }
<div class="scrollable">
What is Lorem Ipsum?
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.

Why do we use it?
It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).
</div>


0
投票

通过这段代码,您应该能够在所有页面上看到这种样式的滚动条,包括页面内的滚动条。 (适用于谷歌浏览器(-webkit))

::-webkit-scrollbar{
width:16px;}
© www.soinside.com 2019 - 2024. All rights reserved.