I would like to know if it's possible to change scrollbar height like this image:
I tried with
::-webkit-scrollbar {max-height: 50%; height: 50%;}
Or
::-webkit-scrollbar-track {max-height: 50%; height: 50%;}
But nothing happened
Thank
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.
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.
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.
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.
to achieve what you want, you need:
.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>
All you need to do is:
::-webkit-scrollbar-track { margin-top: 10px; margin-bottom: 10px; . . . }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With