Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS3 scrollbar styling on a div

How can I style webkit scrollbars with CSS3?

I mean these properties:

::-webkit-scrollbar {     width: 12px; }                      ::-webkit-scrollbar-track {     -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3);      border-radius: 10px; }                      ::-webkit-scrollbar-thumb {     border-radius: 10px;     -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.5);  } 

Here is my div tag:

<div class="scroll"></div> 

Here is my current CSS:

.scroll {     width: 200px; height: 400px;     overflow: hidden; }     
like image 454
Om3ga Avatar asked Sep 09 '12 09:09

Om3ga


People also ask

How do I add a scrollbar to a div in CSS?

To apply, add this style to your div element: overflow-y: scroll; height: XXXpx; The height you specify will be the height of the div and once if you have contents to exceed this height, you have to scroll it.

Can you style a scrollbar 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. In this tutorial, you will learn how to use CSS to customize scrollbars to support modern browsers.

How do you style an overflow scroll?

Setting overflow: hidden hides the scrollbar. Set overflow: scroll to make sure the scrollbar appears all the time. To use the ::webkit-scrollbar property, simply target . scroll before calling it.

Can div have scrollbar?

You need to add style="overflow-y:scroll;" to the div tag. (This will force a scrollbar on the vertical).


2 Answers

Setting overflow: hidden hides the scrollbar. Set overflow: scroll to make sure the scrollbar appears all the time.

To use the ::webkit-scrollbar property, simply target .scroll before calling it.

.scroll {    width: 200px;    height: 400px;     background: red;    overflow: scroll; } .scroll::-webkit-scrollbar {     width: 12px; }  .scroll::-webkit-scrollbar-track {     -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3);      border-radius: 10px; }  .scroll::-webkit-scrollbar-thumb {     border-radius: 10px;     -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.5);  } ​ 

See this live example

like image 93
jacktheripper Avatar answered Sep 20 '22 01:09

jacktheripper


The problem with the css3 scroll bars is that, interaction can only be performed on the content. we can't interact with the scroll bar on touch devices.

like image 33
user2845300 Avatar answered Sep 24 '22 01:09

user2845300