Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change scrollbar height

Tags:

css

I would like to know if it's possible to change scrollbar height like this image:

enter image description here

I tried with

::-webkit-scrollbar {max-height: 50%; height: 50%;} 

Or

::-webkit-scrollbar-track {max-height: 50%; height: 50%;} 

But nothing happened


Thank

like image 797
Alex197 Avatar asked Jun 12 '18 12:06

Alex197


People also ask

How can I increase scrollbar height?

To get the height of the scroll bar the offsetHeight of div is subtracted from the clientHeight of div. OffsetHeight = Height of an element + Scrollbar Height. ClientHeight = Height of an element. Height of scrollbar = offsetHeight – clientHeight.

Can we change height of scrollbar thumb?

the height of the thumb is based in the size of content, you can change the width inside the ::-webkit-scrollbar but the height will always be based on the content.

How do I customize my vertical scrollbar?

Scrollbar Selectors For webkit browsers, you can use the following pseudo elements to customize the browser's scrollbar: ::-webkit-scrollbar the scrollbar. ::-webkit-scrollbar-button the buttons on the scrollbar (arrows pointing upwards and downwards). ::-webkit-scrollbar-thumb the draggable scrolling handle.


2 Answers

It is possible. The first thing you need to know is the structure of a scroll bar. Here I reference a picture from css-tricks.

enter image description here

to achieve what you want, you need:

  • change where 5(scrollbar thumb) start to scroll and stop scrolling
  • fake a scroll track instead of 3.

.page {     position: relative;    width: 100px;     height: 200px;  }    .content {     width: 100%;  }    .wrapper {    position: relative;    width: 100%;     height: 100%;     padding: 0;     overflow-y: scroll;     overflow-x: hidden;     border: 1px solid #ddd;  }    .page::after {     content:'';    position: absolute;    z-index: -1;    height: calc(100% - 20px);    top: 10px;    right: -1px;    width: 5px;    background: #666;  }    .wrapper::-webkit-scrollbar {      display: block;      width: 5px;  }  .wrapper::-webkit-scrollbar-track {      background: transparent;  }        .wrapper::-webkit-scrollbar-thumb {      background-color: red;      border-right: none;      border-left: none;  }    .wrapper::-webkit-scrollbar-track-piece:end {      background: transparent;      margin-bottom: 10px;   }    .wrapper::-webkit-scrollbar-track-piece:start {      background: transparent;      margin-top: 10px;  }
<div class="page">  <div class="wrapper">  <div class="content">  a<br/>  a<br/>  a<br/>  a<br/>a<br/>  a<br/>  a<br/>  a<br/>  a<br/>  a<br/>  a<br/>  a<br/>  a<br/>a<br/>  a<br/>  a<br/>  a<br/>  a<br/>  a<br/>  a<br/>  a<br/>  a<br/>a<br/>  a<br/>  a<br/>  a<br/>  a<br/>  a<br/>  a<br/>  a<br/>  a<br/>a<br/>  a<br/>  a<br/>  a<br/>  a<br/>  </div>  </div>  </div>
like image 132
jilykate Avatar answered Oct 07 '22 01:10

jilykate


All you need to do is:

::-webkit-scrollbar-track {     margin-top: 10px;     margin-bottom: 10px;     .     .     . } 
like image 45
MarchalPT Avatar answered Oct 07 '22 01:10

MarchalPT