How can I get a scrollable sidebar similar to www.youtube.com?

Viewed 3579

I'm trying to get a feature on my page similar to https://www.youtube.com/ Specifically, the tab on the left that includes your playlists, subscriptions, and more. I'm trying to attempt that but without the collapse feature. Can anyone help me out? Thanks

2 Answers

YouTube uses a webkit scrollbar for that section.

Here it is with the same color schemes. Do note that webkit properties are not globally supported.

.container {
  max-height: 200px;
  
  width: 50%;
  
  overflow: auto;
}

.container::-webkit-scrollbar {
  width: 10px;
}

.container::-webkit-scrollbar-track {
  background: transparent; 
}
 
.container::-webkit-scrollbar-thumb {
  background: transparent;
}

.content {
  height: 800px;
}

.container-dark {
  background: #212121;
}

.container-dark:hover::-webkit-scrollbar-thumb {
  background: #4A4A4A; 
}

.container-light {
  background: #fff;
}

.container-light:hover::-webkit-scrollbar-thumb {
  background: #cfcfcf;
}
<div class="container container-dark">
  <div class="content">some content in dark mode</div>
</div>

<div class="container container-light">
  <div class="content">some content in light mode</div>
</div>

YouTube only shows the scrollbar thumb when the container is being hovered, when it isn't being hovered, the scrollbar is transparent.

*::-webkit-scrollbar {
    width: 16px;
}

*::-webkit-scrollbar-track {
    border-radius: 8px;
}

*::-webkit-scrollbar-thumb {
    height: 56px;
    border-radius: 8px;
    border: 4px solid transparent;
    background-clip: content-box;
    background-color: #888;
}

*::-webkit-scrollbar-thumb:hover {
    background-color: #555;
}
Related