【问题标题】:Style the scrollbar with css in Google Chrome (-webkit)在 Google Chrome (-webkit) 中使用 css 设置滚动条样式
【发布时间】:2022-01-30 03:26:27
【问题描述】:

有人可以帮帮我吗?我想为滚动条做一个简单的样式。我在互联网上找到了一些信息并尝试了它,但由于某些原因它似乎并没有真正起作用。刷新页面时滚动条看起来不错,但是一旦您触摸滚动条,它就会变得疯狂。它填充了很多颜色,你无法理解那是滚动条。

这里是你触摸之前的样子 - 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


    【解决方案1】:

    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

    【讨论】:

    • 两个链接都坏了
    【解决方案2】:
    .invisible-scrollbar {
      scrollbar-width: none;
    }
    .invisible-scrollbar::-webkit-scrollbar {
      display: none;
    }
    

    【讨论】:

      【解决方案3】:

      对于在 2021 年 12 月之后检查此答案的任何人,我添加了带有 @orel 答案的 sn-p(更新了代码,还添加了一些 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>

      【讨论】:

      • 在 chrome mobile iphone xsmax 上不起作用
      • 根据caniuse.com/css-scrollbar 在 iOS 14(包括 15.4)之后由于某种原因不支持 CSS 滚动条样式(无论是在 safari 上还是在 Chrome 上)
      猜你喜欢
      • 2011-11-05
      • 2011-09-04
      • 2011-07-07
      • 2019-05-15
      • 2020-05-22
      • 2019-01-14
      • 2021-09-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多