HTML5 : Create custom scrollbar



Customizing scrollbars has become a new trend nowadays.Learn how to use the vendor-
                                                                                   prefixed properties



HTML5

These days, customizing scrollbars is back, but it's WebKit this time. It's a bit better now, because the properties are vendor-prefixed (e.g. ::-webkit-scrollbar).  WebKit now supports styling of the scrollbars in overflow sections, listboxes, dropdown menus and textareas. David Hyatt blogged in early 2009 and put together an example page of just about every combination of scrollbar possibilities you could ever want.

Scrollbar Parts

::-webkit-scrollbar              { /* 1 */ }
::-webkit-scrollbar-button       { /* 2 */ }
::-webkit-scrollbar-track        { /* 3 */ }
::-webkit-scrollbar-track-piece  { /* 4 */ }
::-webkit-scrollbar-thumb        { /* 5 */ }
::-webkit-scrollbar-corner       { /* 6 */ }
::-webkit-resizer                { /* 7 */ }


Each of these objects can be styled with borders, shadows, background images, and so on to create completely custom scrollbars that will still honor the settings of the operating system as far as button placement and click behavior.



The Different States

These are the pseudo class selectors. They allow for more specific selection of the parts, like when the scrollbar is in different states.This part is a part from Dave Hyatt post.
:horizontal – The horizontal pseudo-class applies to any scrollbar pieces that have a horizontal orientation.
:vertical – The vertical pseudo-class applies to any scrollbar pieces that have a vertical orientation.
:decrement – The decrement pseudo-class applies to buttons and track pieces. It indicates whether or not the button or track piece will decrement the view’s position when used (e.g., up on a vertical scrollbar, left on a horizontal scrollbar).
:increment – The increment pseudo-class applies to buttons and track pieces. It indicates whether or not a button or track piece will increment the view’s position when used (e.g., down on a vertical scrollbar, right on a horizontal scrollbar).
:start – The start pseudo-class applies to buttons and track pieces. It indicates whether the object is placed before the thumb.
:end – The end pseudo-class applies to buttons and track pieces. It indicates whether the object is placed after the thumb.
:double-button – The double-button pseudo-class applies to buttons and track pieces. It is used to detect whether a button is part of a pair of buttons that are together at the same end of a scrollbar. For track pieces it indicates whether the track piece abuts a pair of buttons.
:single-button – The single-button pseudo-class applies to buttons and track pieces. It is used to detect whether a button is by itself at the end of a scrollbar. For track pieces it indicates whether the track piece abuts a singleton button.
:no-button – Applies to track pieces and indicates whether or not the track piece runs to the edge of the scrollbar, i.e., there is no button at that end of the track.
:corner-present – Applies to all scrollbar pieces and indicates whether or not a scrollbar corner is present.
:window-inactive – Applies to all scrollbar pieces and indicates whether or not the window containing the scrollbar is currently active. (In recent nightlies, this pseudo-class now applies to ::selection as well. We plan to extend it to work with any content and to propose it as a new standard pseudo-class.
BASIC HTML & CSS


<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>THEWWWDESIGNERS</title>

<style>
body {
font-family: 'Lucida Grande', 'Helvetica Neue', sans-serif;
font-size: 13px;
}


.custom_scrollbar {
margin: 20px auto;
height: 300px;
width: 500px;
overflow: scroll;
padding: 0 20px 0 0;
}


.custom_scrollbar::-webkit-scrollbar {
width: 10px;
height: 10px;
}


.custom_scrollbar::-webkit-scrollbar-track {
background-color: rgba(113,112,107,0.1);
-webkit-border-radius: 5px;
}


.custom_scrollbar::-webkit-scrollbar-thumb:vertical {
background-color: rgba(0,0,0,.2);
-webkit-border-radius: 6px;
}


.custom_scrollbar::-webkit-scrollbar-thumb:vertical:hover,
.custom_scrollbar::-webkit-scrollbar-thumb:horizontal:hover {
background: red;
}


.custom_scrollbar::-webkit-scrollbar-thumb:horizontal {
background-color: rgba(0,0,0,.2);
-webkit-border-radius: 6px;
}


</style>
</head>
<body>
<div class="custom_scrollbar">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.
In bibendum augue in leo elementum nec volutpat nunc fringilla.
Cras tincidunt tempor dolor sed viverra. Curabitur convallis
ligula vel arcu vestibulum eget tempus lectus tristique.
Vestibulum dapibus lobortis ante, sed iaculis nisl pretium eu.


Vivamus sed augue neque. Donec eu convallis urna. Cras sed
dui non lacus porttitor pulvinar. In aliquet, ipsum in
eleifend dignissim, est mauris laoreet sapien, in pharetra
orci augue et augue. Morbi dignissim elementum magna. Integer
venenatis congue nulla, a volutpat erat egestas ac. Proin eget
tincidunt risus. Nunc laoreet rhoncus justo eget lobortis.
Nullam at justo nec nibh volutpat adipiscing.</p>


<pre>


Long text Long text Long text Long text Long text Long text Long text Long text Long text Long text 
Long text Long text Long text Long text Long text Long text Long text Long text Long text Long text 
Long text Long text Long text Long text Long text Long text Long text Long text Long text Long text


</pre>


<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.
In bibendum augue in leo elementum nec volutpat nunc fringilla.
Cras tincidunt tempor dolor sed viverra. Curabitur convallis
ligula vel arcu vestibulum eget tempus lectus tristique.
Vestibulum dapibus lobortis ante, sed iaculis nisl pretium eu.
Vivamus sed augue neque. Donec eu convallis urna. Cras sed
dui non lacus porttitor pulvinar. In aliquet, ipsum in
eleifend dignissim, est mauris laoreet sapien, in pharetra
orci augue et augue. Morbi dignissim elementum magna. Integer
venenatis congue nulla, a volutpat erat egestas ac. Proin eget
tincidunt risus. Nunc laoreet rhoncus justo eget lobortis.
Nullam at justo nec nibh volutpat adipiscing.</p>


<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.
In bibendum augue in leo elementum nec volutpat nunc fringilla.
Cras tincidunt tempor dolor sed viverra. Curabitur convallis
ligula vel arcu vestibulum eget tempus lectus tristique.
Vestibulum dapibus lobortis ante, sed iaculis nisl pretium eu.
Vivamus sed augue neque. Donec eu convallis urna. Cras sed
dui non lacus porttitor pulvinar. In aliquet, ipsum in
eleifend dignissim, est mauris laoreet sapien, in pharetra
orci augue et augue. Morbi dignissim elementum magna. Integer
venenatis congue nulla, a volutpat erat egestas ac. Proin eget
tincidunt risus. Nunc laoreet rhoncus justo eget lobortis.
Nullam at justo nec nibh volutpat adipiscing.</p>


<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.
In bibendum augue in leo elementum nec volutpat nunc fringilla.
Cras tincidunt tempor dolor sed viverra. Curabitur convallis
ligula vel arcu vestibulum eget tempus lectus tristique.
Vestibulum dapibus lobortis ante, sed iaculis nisl pretium eu.
Vivamus sed augue neque. Donec eu convallis urna. Cras sed
dui non lacus porttitor pulvinar. In aliquet, ipsum in
eleifend dignissim, est mauris laoreet sapien, in pharetra
orci augue et augue. Morbi dignissim elementum magna. Integer
Venenatis congue nulla, a volutpat erat egestas ac. Proin eget
tincidunt risus. Nunc laoreet rhoncus justo eget lobortis.
Nullam at justo nec nibh volutpat adipiscing.</p>


</div>
</body>
</html>

The width and height properties on the scrollbar element indicate the width of the vertical scrollbar and the height of the horizontal scrollbar.