Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scrollbar thumb height in css

Is the height of scroll thumb set as default according to scroll-able area? If not, can I set scrollbar thumb height? If it is possible how? I tried to do it the following way.

body::-webkit-scrollbar-thumb {
  background-color: darkgrey;
  outline: 1px solid slategrey;
  height: 5px;
}

But it have no impact on the page. Please help. Thanks in advance.

like image 992
AngularDoubts Avatar asked Aug 18 '17 11:08

AngularDoubts


People also ask

What is thumb in scrollbar?

a box or “thumb” within a scrollbar that allows the user to move to a specific region by dragging the box to the appropriate location within the scrollbar. Also called a “scrollbox” or “elevator”.

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.

How do I change the scrollbar position in CSS?

We can use the CSS “::-webkit-scrollbar” property which is responsible for changing the shape, color, size, shade, shadow, etc. of the scroll bar. But, here the property which we will use is the direction property of CSS for changing the position of the scroll bar.


3 Answers

I don't think so, 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.

::-webkit-scrollbar              { /* 1 */ }
::-webkit-scrollbar-button       { /* 2 */ }
::-webkit-scrollbar-track        { /* 3 */ }
::-webkit-scrollbar-track-piece  { /* 4 */ }
::-webkit-scrollbar-thumb        { /* 5 */ }
::-webkit-scrollbar-corner       { /* 6 */ }
::-webkit-resizer                { /* 7 */ }

css-tricks

enter image description here

Source

like image 140
Marcelo Formentão Avatar answered Oct 07 '22 11:10

Marcelo Formentão


If you want to set fixed min height to the scrollbar thumb even when scroll. we can set like below:

::-webkit-scrollbar-thumb {
    min-height: 40px;
   }
like image 3
Bharat chaudhari Avatar answered Oct 07 '22 13:10

Bharat chaudhari


You can do this:

::-webkit-scrollbar-thumb{
    background-color: transparent;
    border-top: 60px solid green /*or any height and color you want*/;
}

that will make the height constant with value of 60px, but pay attention that it will not be able scroll to the very end because of the transparent space.

like image 1
Eliya_101 Avatar answered Oct 07 '22 11:10

Eliya_101