16

I want to make scrollbar that overlaps the page. I wonder if there is a way to do it with pure CSS. I read an article about styling scrollbars with CSS (https://css-tricks.com/custom-scrollbars-in-webkit) but I didn't get a result I wanted. I think it would be possible to do it with some JavaScript and HTML element with fixed position, but I prefer to do it with CSS. scrollbar

Nejc Jezersek
  • 621
  • 1
  • 9
  • 19

3 Answers3

31

I have this same requirement in my project.

Here is the solution:

overflow: overlay

Hope it helps

RienNeVaPlu͢s
  • 7,442
  • 6
  • 43
  • 77
2

As Anugraha Acharya said, the only CSS option is:

overflow: overlay;

But it is worth noting that this has been deprecated, so there is no telling how long it will work in Chromium / Webkit.

It is not supported in Firefox so, you will have to do the following to ensure Firefox can scroll too:

overflow: scroll;
overflow: overlay;

With this, Firefox will render like the "Normal" diagram in the original post and Chromium will render like "how I want scroll to look". Also, if Chromium ever drops it it will still be usable.

This currently works as of January 2022.


I believe, by deprecated, Mozilla means that it was never officially added rather than it was considered and has now been dropped. So, hopefully, it will be considered and made official. In the meantime, you take your own risk.

atwright147
  • 3,694
  • 4
  • 31
  • 57
  • 1
    Firefox likes to call things "deprecated" when they mean "works everywhere but in Firefox". Take MDN with a grain of salt for things like that. – Glenn Maynard Oct 14 '22 at 01:16
-4

You can try changing the background of the Scrollbar to transparent-

::-webkit-scrollbar-track {background: transparent}
theLearner
  • 363
  • 4
  • 16