Transparent scrollbar with css

后端 未结 8 1633
面向向阳花
面向向阳花 2020-12-05 04:15

Now use this code (and many variations of this), but scroll track get dark-grey color, something like #222222 or near this. Find many examples, but all of them give same res

相关标签:
8条回答
  • 2020-12-05 04:49
        .scrollable-content {
          overflow-x:hidden;
          overflow-y:scroll; // manage scrollbar content overflow settings
        }
        .scrollable-content::-webkit-scrollbar {
          width:30px; // manage scrollbar width here
        }
        .scrollable-content::-webkit-scrollbar * {
          background:transparent; // manage scrollbar background color here
        }
        .scrollable-content::-webkit-scrollbar-thumb {
          background:rgba(255,0,0,0.1) !important; // manage scrollbar thumb background color here
        }
    
    0 讨论(0)
  • 2020-12-05 04:53

    To control the background-color of the scrollbar, you need to target the primary element, instead of -track.

    ::-webkit-scrollbar {
        background-color: blue;
    }
    
    ::-webkit-scrollbar-track {
        -webkit-box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.3);
    }
    

    I haven't succeeded in rendering it transparent, but I did manage to set its color.

    Since this is limited to webkit, it is still preferable to use JS with a polyfill: CSS customized scroll bar in div

    0 讨论(0)
  • 2020-12-05 04:56

    Embed this code in your css.

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

    /* Track */

    ::-webkit-scrollbar-track {
        -webkit-box-shadow: none;
    }
    

    /* Handle */

    ::-webkit-scrollbar-thumb {
        background: white;
        -webkit-box-shadow: none;
    }
    
    ::-webkit-scrollbar-thumb:window-inactive {
        background: none;
    }
    
    0 讨论(0)
  • 2020-12-05 04:56

    Try this one, it works fine for me.

    In CSS:

    ::-webkit-scrollbar
    {
        width: 0px;
    }
    ::-webkit-scrollbar-track-piece
    {
        background-color: transparent;
        -webkit-border-radius: 6px;
    }
    

    and here is the working demo: https://jsfiddle.net/qpvnecz5/

    0 讨论(0)
  • 2020-12-05 05:01

    if you don't have any content with 100% width, you can set the background color of the track to the same color of the body's background

    0 讨论(0)
  • 2020-12-05 05:06

    With pure css it is not possible to make it transparent. You have to use transparent background image like this:

    ::-webkit-scrollbar-track-piece:start {
        background: transparent url('images/backgrounds/scrollbar.png') repeat-y !important;
    }
    
    ::-webkit-scrollbar-track-piece:end {
        background: transparent url('images/backgrounds/scrollbar.png') repeat-y !important;
    }
    
    0 讨论(0)
提交回复
热议问题