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

zysjyyx4  于 2023-02-27  发布在  Go
关注(0)|答案(4)|浏览(242)

有人能帮帮我吗?我想为滚动条做一个简单的样式。我在互联网上找到了一些信息,并尝试了一下,但似乎它并不真正工作的一些原因。滚动条看起来很好,当刷新页面,但只要你触摸滚动条,它疯了。它充满了很多颜色,你不能理解,这是一个滚动条。
这是触摸前的外观-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); }

谢谢大家干杯Alex

2ul0zpep

2ul0zpep1#

Here is an example that works

::-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

i7uq4tfw

i7uq4tfw2#

.invisible-scrollbar {
  scrollbar-width: none;
}
.invisible-scrollbar::-webkit-scrollbar {
  display: none;
}
nwsw7zdq

nwsw7zdq3#

对于2021年12月之后查看这个答案的人,我添加了一个带有@orel answer的代码片段(更新了代码,还添加了一些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>
p5cysglq

p5cysglq4#

通过这段代码,你应该可以在所有页面上看到这种风格的滚动条,包括页面内的滚动条。(这是谷歌浏览器(-webkit))

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

相关问题