Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom webkit scrollbar position

Tags:

scrollbar

I have a custom webkit scrollbar like this:

::-webkit-scrollbar{
  background: transparent;
  width: 10px;
}
::-webkit-scrollbar-thumb{
  background: #999 !important;
}

So it renders a grey custom scrollbar instead of the standard one. However, it is stuck to the right side of the page. I know I can change this by adding a margin, padding or border to my body but I am using fullscreen (on backgrounds) images. So when I try this all the images are affected by this too, which I do not want. So I tried to position the scrollbar but this does not work (as it is not an element but a user agent property...

So I'm looking for a way (without using another plugin) to customize the toolbar so that it is offset from the side.

Or, if possible that I can make the scrollbar offset in a div.

Secondly, I'm looking for a way that I can make the "track" of the scrollbar transparet. So only a handle.

Thanks in advance!

like image 601
Robert Luyt Avatar asked Nov 13 '13 00:11

Robert Luyt


People also ask

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.

How do I add a margin to a CSS WebKit scrollbar?

Use the ::-webkit-scrollbar selector, give the bar a fixed with of x pixels. then set the left property to some -px value.

Can you style scrollbar CSS?

In September 2018, W3C CSS Scrollbars defined specifications for customizing the appearance of scrollbars with CSS. As of 2020, 96% of internet users are running browsers that support CSS scrollbar styling. However, you will need to write two sets of CSS rules to cover Blink and WebKit and also Firefox browsers.

How do I customize my horizontal scroll bar?

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

If you are still looking for for the answer (or somebody else is, like I was) - here is a definitive article about webkit scrollbars.
Answering Your first question - I'd suggest that you put all your scrollable content in a div with 100% height and 90% width - the 10% left on the right would be your offset. Like that:

.superDiv{
  height:100%;
  width:90%;
  position:fixed;
}
body{ overflow: hidden }

The second question - you're looking for

::-webkit-scrollbar-track-piece {
  background:transparent;
}

But as Apple people are pushing for no-scrollbar web browsing, only the properties set by CSS are visible, so you don't have to change the track-piece.

like image 62
adamboro Avatar answered Sep 24 '22 14:09

adamboro


Clever solution I found recently was to put the border on the right hand side of the screen / div that contains scrollbar:

<div class="yourdiv">
border-right: 5px solid #(background_color);
</div>
like image 37
user3210787 Avatar answered Sep 21 '22 14:09

user3210787