CSS customized scroll bar in div

后端 未结 19 1825
夕颜
夕颜 2020-11-21 11:05

How can I customize a scroll bar via CSS (Cascading Style Sheets) for one div and not the whole page?

19条回答
  •  北荒
    北荒 (楼主)
    2020-11-21 12:01

    There is a way by which you can apply custom scrollbars to custom div elements in your HTML documents. Here is a an example which helps. https://codepen.io/adeelibr/pen/dKqZNb But as a gist of it. You can do something like this.

    CSS file looks like this.

    .scrollbar
    {
      margin-left: 30px;
      float: left;
      height: 300px;
      width: 65px;
      background: #F5F5F5;
      overflow-y: scroll;
      margin-bottom: 25px;
    }
    
    .force-overflow
    {
      min-height: 450px;
    }
    
    #style-1::-webkit-scrollbar-track
    {
      -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3);
      border-radius: 10px;
      background-color: #F5F5F5;
    }
    
    #style-1::-webkit-scrollbar
    {
      width: 12px;
      background-color: #F5F5F5;
    }
    
    #style-1::-webkit-scrollbar-thumb
    {
      border-radius: 10px;
      -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,.3);
      background-color: #555;
    }
    

提交回复
热议问题