Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

It is possible to specify the scrollbar image with HTML5?

I need to display a custom scrollbar. I would like to avoid using a jQuery plugin if possible. So can I so something like this with HTML5 & CSS3 ? :

.myScrollableBox {
  width: 200px;
  height: 500px;

  /* Display scrollbar if content is bigger than the box */
  overflow: auto;

  /* This doesn't work, but can I do something similar? */
  scrollbar-image: url(/images/myscrollbar.png); 
}
like image 732
Benjamin Crouzier Avatar asked Sep 02 '25 16:09

Benjamin Crouzier


1 Answers

It's actually possible, if browser does support styling of toolbar elements (= is based on WebKit). Although it's not mentioned in many tutorials (such as this brilliant one, for example), you can just use background-url property to use custom image instead of color.

For example, in this page I've changed (in Chrome Developer Tools) styling to...

::-webkit-scrollbar-thumb {
  -webkit-border-radius: 10px;
  border-radius: 10px;
  background: url('http://cdn.css-tricks.com/wp-content/themes/CSS-Tricks-10/images/header-demos.jpg');
  -webkit-box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.5);
}

... and voila, I have some cyanid scroller. )

like image 128
raina77ow Avatar answered Sep 05 '25 06:09

raina77ow