Search code examples
htmlcssscrollbararrows

How to add arrows with -webkit-scrollbar-button


I have a custom scrollbar. Since I did that, the arrows of the scrollbar are not shown anymore.

.scrollbar::-webkit-scrollbar-thumb {
    background-color: ##00a7e0;
  }

  .scrollbar::-webkit-scrollbar-track {
    background-color: #F5F5F5;
  }

  .scrollbar::-webkit-scrollbar-button {
    ????;
  }

What do I have to add in .scrollbar::-webkit-scrollbar-button that my arrows are shown again?


Solution

  • (Super late to the party, but still)

    You can style scrollbar buttons using ::-webkit-scrollbar-button selector (see this blog post for a full breakdown on the webkit scrollbar pseudo selectors), but getting them to show arrows is much trickier, and most people seem to either use background images or skip buttons altogether.

    Here's a solution using CSS triangles for arrows:

    https://stackoverflow.com/a/46229219/1202275

    and another one (based on the one above, vertical scrollbar only but the idea is the same):

    ::-webkit-scrollbar {
      width: 16px;
      border: 5px solid white;
    
    }
    
    ::-webkit-scrollbar-thumb {
      background-color: #b0b0b0;
      background-clip: padding-box;
      border: 0.05em solid #eeeeee;
    }
    
    ::-webkit-scrollbar-track {
      background-color: #bbbbbb;
    }
    /* Buttons */
    ::-webkit-scrollbar-button:single-button {
      background-color: #bbbbbb;
      display: block;
      border-style: solid;
      height: 13px;
      width: 16px;
    }
    /* Up */
    ::-webkit-scrollbar-button:single-button:vertical:decrement {
      border-width: 0 8px 8px 8px;
      border-color: transparent transparent #555555 transparent;
    }
    
    ::-webkit-scrollbar-button:single-button:vertical:decrement:hover {
      border-color: transparent transparent #777777 transparent;
    }
    /* Down */
    ::-webkit-scrollbar-button:single-button:vertical:increment {
      border-width: 8px 8px 0 8px;
      border-color: #555555 transparent transparent transparent;
    }
    
    ::-webkit-scrollbar-button:vertical:single-button:increment:hover {
      border-color: #777777 transparent transparent transparent;
    }
    

    (https://codepen.io/DarthVeyda/pen/eLLbXa)