Skip to main content

CSS: How To Create Custom Scrollbar For Webkit Supported Browsers

One of eye catching thing of Gmail new updates was its scrollbar. First I thought it would be an html element represented by some kind of Javascript. But after some time I realized that it was not Javascript effect rather it is a CSS effects for scrollbars.



One amazing thing about this scrollbars are, they can be represented in different style for different HTML elements within same webpage.

Today we will see the implementation of such scrollbar for Webkit supported browsers.

First we will look at basic CSS properties of scrollbar.

::-webkit-scrollbar             
::-webkit-scrollbar-thumb       
::-webkit-scrollbar-track       
::-webkit-scrollbar-button      
::-webkit-scrollbar-track-piece 
::-webkit-scrollbar-corner      
::-webkit-resizer

Following image shows location these properties within scrollbar.


Now let’s look at the one basic example

            body{
                min-height: 1000px;
            }
            ::-webkit-scrollbar{
                width: 10px;
                margin:5px;
            }
            ::-webkit-scrollbar-track{
                background: #fff;
                -webkit-box-shadow: inset 1px 1px 2px rgba(0,0,0,0.1);

            }
            ::-webkit-scrollbar-thumb{
                background: #aaa;
                box-shadow: 0px 0px 1px rgba(0,0,0,0.5);
            }
            ::-webkit-scrollbar-thumb:hover{
                background: #888;
            }
            ::-webkit-scrollbar-thumb:active{
                background: #444;
            }




You can also customize scrollbars of overflow HTML elements, like this
 
<div id="custom-scrollbar">
            <div class="content">
                <!-- some HTML stuff -->
            </div>
        </div>

And CSS code

#custom-scrollbar {
                width: 20%;
                height: 300px;
                overflow: auto;
                background: #eee;
            }
            .content{
                height: 600px;
            }
            
            #custom-scrollbar::-webkit-scrollbar{
                width: 10px;
                margin:5px;
            }
            #custom-scrollbar::-webkit-scrollbar-track{
                background: #fff;
                -webkit-box-shadow: inset 1px 1px 2px rgba(0,0,0,0.1);
                border-radius: 10px;
            }
            #custom-scrollbar::-webkit-scrollbar-thumb{
                background: #F77;
                box-shadow: 0px 0px 1px rgba(0,0,0,0.5);
                border-radius: 10px;
            }
            #custom-scrollbar::-webkit-scrollbar-thumb:hover{
                background: #A55;
            }
            #custom-scrollbar::-webkit-scrollbar-thumb:active{
                background: #744;
            }
Hope you would like this post.

Comments

Popular posts from this blog

AngularJs Tutorial: Getting Started

This tutorial will help you to create a dynamic web application using power of AngularJs. ·   What is AngularJs AngularJs is javascript MVC framework (maintained by Google) which molds static HTML application to dynamic web application. That was a brief introduction, you can find more information on Wiki and AngularJS Site . AngularJs follows MVC pattern to separate out model from view and manage it by controller. See this image Goal of using AngularJs is to convert static HTML template to dynamic (Angular) template.   ·   How to convert static template to dynamic (Angular) Template Now consider the following static HTML template which contain list of movies title. <html> <head></head> <body>   <h1>Upcoming Movies</h1> <ul>     <li>       <span>Godzilla</span>     </li> <li>       <span>Batman vs Superman</span>     </li> <li>       <span>Sta

Abstract Factory design pattern analysis

What is Abstract Factory design pattern?     The intent or definition of Abstract Factory is “ Provide an interface for creating families of related or dependent objects without specifying their concrete classes ” It is kind of an obscure definition, in order to understand it we need to break it into meaningful pieces. 1.  " Provide an interface "  When we talk about Abstract Factory we talk about interface not abstract class , Basically this design pattern gives us an Interface, like Interface in Java, C# , Typescript (abstract class).    Why interface?  Whenever we talk about any design pattern, it emphasizes more on how we are going to use it rather than implement it. Interface is always the right type to prefer because concrete class creates tight coupling whereas an interface isolates it from the rest of the system. At runtime we can get different solution, without updating our code. For example interface SecurityFactory

AngularJs Tutorials : Bootstrap

Every application starts with bootstrap process which initialize application and wire it other with dependencies and configurations. AngularJs is not different from other application. It also starts application with bootstrap process. Following operation happens inside AngularJs bootstrap process. Load application module. Create dependency injector and load dependencies. Compile HTML and create scope for application. All these steps happens inside angular.js scripting file. therefore we need to include it first. we can include it inside HEAD tag or at end of BODY tag. Note: Adding angular.js file at end of body tag will allow browser to load of HTML elements without any delay and afterwards load angular.js and begin bootstrapping process. You can get angular.js source file from https://code.angularjs.org/ <script src= ”https://code.angularjs.org/1.3.0/angular.js” type= ”text/javascript” > AngularJs bootstrap process happens on docum