Scrollbar track thinner than thumb

后端 未结 9 1486
时光说笑
时光说笑 2021-02-19 10:39

I am trying to style a scrollbar using css and I want to achieve the following look (ignore the background):

In other words, I want the thumb to be thicker than

相关标签:
9条回答
  • 2021-02-19 11:36

    A css-only solution that does not use any images involves using the scrollbar borders to produce the desired effect. The trick is to match the scrollbar element's border colors to your container's background color. However, this won't work on complex backgrounds, like the OP's.

    Example: https://jsfiddle.net/vsj6qb8c/6/

    body {
      --container-background-color: #C7C7C7;
    }
    
    .outer {
        height: 150px;
        overflow-y: scroll;
      background-color: var(--container-background-color);
    }
    
    .force-overflow {
        min-height: 450px;
    }
    
    ::-webkit-scrollbar {
        width: 20px;
      border-width: 5px;
    }
    
    ::-webkit-scrollbar-track-piece {
        background-color: #757575;
      border-color: var(--container-background-color);
      border-width: 2px 9px 2px 9px;
      border-style: solid;
    }
    
    ::-webkit-scrollbar-thumb {
        border-radius: 7px;
        background-color: #51545E;
      border-color: var(--container-background-color);
      border-style: solid;
      border-width: 1px 7px 1px 7px;
    }
    
    0 讨论(0)
  • 2021-02-19 11:37

    Here is nearly matching code with css. You just have to change the color or add image in ::-webkit-scrollbar-thumb try small image if you want and you may also need to adjust the position.

     .container {
          margin: 40px auto;
          width: 1000px;
          height: 200px;
          overflow-y: scroll;
        }
        .container::-webkit-scrollbar {
          width: 20px;
        }
        .container::-webkit-scrollbar-track {
          background: tomato;
          border-left: 9px solid white;
          border-right: 9px solid white;
        }
        ::-webkit-scrollbar-thumb {
            border-radius: 10px;
            -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.5);      
          
             /*background-image:url( http://i.imgur.com/ygGobeC.png);*/
        }
        .container .item {
          height: 20px;
          margin-bottom: 5px;
          background: silver;
        }
        .container .item:last-child {
          margin-bottom: 0;
        } 
        .container {
            direction:rtl;
          }
     <div class="container">
            <div class="item"></div>
            <div class="item"></div>
            <div class="item"></div>
            <div class="item"></div>
            <div class="item"></div>
            <div class="item"></div>
            <div class="item"></div>
            <div class="item"></div>
            <div class="item"></div>
            <div class="item"></div>
            <div class="item"></div>
            <div class="item"></div>
            <div class="item"></div>
            <div class="item"></div>
            <div class="item"></div>
            <div class="item"></div>
            <div class="item"></div>
            <div class="item"></div>
            <div class="item"></div>
            <div class="item"></div>
        </div>
    
     

    0 讨论(0)
  • 2021-02-19 11:38

    As far as I can tell it is not possible to achieve this particular effect with pure CSS, as scroll bar styling these days is very limited. Also FireFox wont allow custom scroll bar styles so you will have to use a plugin for cross browser styling.

    The jQuery plugin below seems to have very similar styles to what you have posted and is recommended a lot. I haven't tried it myself but jQuery plugins tend to be quite simple to implement and customize to your needs.

    http://manos.malihu.gr/jquery-custom-content-scroller/

    0 讨论(0)
提交回复
热议问题