Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the height of a scrollbar thumb?

Is there any way to change the height of a scrollbar to a fixed height and change the amount of content scrolled accordingly? This is my current css code.

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

/* Track */
::-webkit-scrollbar-track {
    box-shadow: inset 0 0 5px #003B7C; 
    border-radius: 10px;
    background: white;
    border-left: 8px solid rgba(255,255,255,0);
    border-right: 8px solid rgba(255,255,255,0);
    background-clip: content-box;
}

/* Handle */
::-webkit-scrollbar-thumb {
    background: linear-gradient(to right,#003B7C, #00538B, #83BBE6); 
    border-radius: 8px;
}
like image 511
Sruthi Varghese Avatar asked Jun 06 '18 14:06

Sruthi Varghese


People also ask

How do I get the height of my thumb scrollbar?

The thumb (I've heard people call it a scrubber) size should be the size of the viewport (in your example 200px) divided by the size of the content (600px). So, your thumb should take up 1/3rd the available height. The available height is the size of the scroll bar minus the arrows.

How do I change the size of my scrollbar?

Double-click/tap on ScrollHeight. The Edit String window will open with the default value of -255. That is the standard size of the scrollbars you see on Windows. To change the Scrollbars height to your liking, enter a value between -120 (smaller) to -1500 (larger) for the size you want, and click/tap on OK.

How can I make my scrollbar track thinner than my thumb?

The trick here is to give the scrollbar the same width as your "thumb". Then you will want to give the "track" a transparent background, with a background image. Repeat the background image vertically, and you'll have yourself a good looking scroll bar.

How do I change the position of my scroll bar?

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.


2 Answers

https://jsfiddle.net/j6gmobuz/6/

.visible-scrollbar::-webkit-scrollbar-thumb {
    background-color: #acacac;
    border-radius: 50px;
    height: 120px;
}

I was able to partly control the height of the scroll thumb by simply using height property on "::-webkit-scrollbar-thumb". It appears to be minimum height value which I wasn't able to set a new value below it.

Maybe this could help.

like image 62
badigard Avatar answered Oct 01 '22 22:10

badigard


Scrollbar height is not about "::-webkit-scrollbar", it's about content height. You must give "max-height" and "overflow-y" to your content. You can't define height for a vertical scrollbar. That is dependent on content size.

Let's say you have a thing like this:

<div class="wrapper">
  <p>Lorem ipsum dolor sit amet consectetur, adipisicing elit. Repellat adipisci itaque beatae quisquam corporis. Eos praesentium temporibus autem assumenda enim aspernatur culpa, esse quam, optio, molestias dolor sapiente vel deserunt!</p>
  <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Impedit provident illo placeat nemo sint dolores quod temporibus, doloremque repudiandae, cum architecto, nostrum aut ipsum atque. Aspernatur autem error unde praesentium!</p>
</div>

If you write CSS like this:

.wrapper {
    width: 300px;
    max-height: 200px;
    overflow-y: scroll;
}

you can specify height.

Look this codepen.

like image 40
Mustafa Turhan Avatar answered Oct 01 '22 23:10

Mustafa Turhan