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

Ale*_*las 29 css webkit google-chrome scrollbar

有人能帮帮我吗?我想为滚动条做一个简单的样式.我在互联网上找到了一些信息并试了一下,但似乎由于某些原因它并没有真正起作用.刷新页面时滚动条看起来很好,但只要触摸滚动条就会发疯.它充满了很多颜色,你无法理解这是一个滚动条.

在你触摸之前它的外观如何 - 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); }
Run Code Online (Sandbox Code Playgroud)

谢谢你们.干杯.亚历克斯

ore*_*rel 53

这是一个有效的例子:

::-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;
}
Run Code Online (Sandbox Code Playgroud)

或者您可以使用jScrollPane.

  • 两个链接都坏了 (9认同)

小智 5

.invisible-scrollbar {
  scrollbar-width: none;
}
.invisible-scrollbar::-webkit-scrollbar {
  display: none;
}
Run Code Online (Sandbox Code Playgroud)


Ber*_*rci 5

对于 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;
 }
Run Code Online (Sandbox Code Playgroud)
<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>
Run Code Online (Sandbox Code Playgroud)