CSS3 custom scroll bar style::webkit-scrollbar sample code detailed explanation

CSS3 custom scroll bar style::webkit-scrollbar sample code detailed explanation

The default scroll bar style in Windows is ugly, and there are many places in the project where scroll bars are displayed, so I went back to look at CSS3 and found that it is possible to customize the scroll bar style without plug-ins, which is exactly what I want.

The code is as follows:

/ Define the scroll bar height and width and the background height and width to correspond to the size of the horizontal and vertical scroll bars respectively /

::-webkit-scrollbar  
{  
    width: 6px;  
    height: 6px;  
    background-color: #F5F5F5;  
}

/ Define the inner shadow + rounded corners of the scroll bar track /

::-webkit-scrollbar-track  
{  
    -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3);  
    border-radius: 10px;  
    background-color: #FFF;  
}

/ Define slider inner shadow + rounded corners /

::-webkit-scrollbar-thumb  
{  
    border-radius: 10px;  
    -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,.3);  
    background-color: #AAA;  
}

Specific meaning and other settings:

::-webkit-scrollbar The entire scroll bar
::-webkit-scrollbar-thumb The small square inside the scroll bar can be moved up and down (or left or right, depending on whether it is a vertical scroll bar or a horizontal scroll bar)
::-webkit-scrollbar-track The track of the scroll bar (with Thumb inside)
::-webkit-scrollbar-button The buttons at both ends of the scrollbar track allow you to fine-tune the position of the small square by clicking it.
::-webkit-scrollbar-track-piece Inner track, the middle part of the scroll bar (removed)
::-webkit-scrollbar-corner The corner, where the two scroll bars meet
::-webkit-resizer A small control at the intersection of two scroll bars for resizing elements by dragging

:horizontal  
//The horizontal pseudo-class applies to any horizontal scroll bar: vertical  
//The vertical pseudo-class applies to any vertical scroll bar: decrement  
//The decrement pseudo-class applies to buttons and track pieces. A button or track fragment that represents a decrement, such as a region or button that can move a region up or to the right: increment  
//The increment pseudo-class applies to buttons and track pieces. Indicates an incremental button or track fragment, such as a region or button that can move a region down or to the left: start  
//The start pseudo-class applies to buttons and track pieces. Indicates whether the object (button track fragment) is placed in front of the slider: end  
//end pseudo-class applies to buttons and track pieces. Indicates whether the object (button track fragment) is placed behind the slider: double-button  
//The double-button pseudo-class applies to both buttons and track pieces. Determines whether the track ends at a pair of buttons. That is, the orbital debris is next to a pair of buttons together.  
  
:single-button  
//The single-button pseudo-class applies to both buttons and track pieces. Determines whether the end of the track is a button. That is, the orbital fragments are next to a separate button.  
  
:no-button  
The no-button pseudo-class indicates that there is no button at the end of the track.  
  
:corner-present  
//The corner-present pseudo-class indicates whether the corner of the scroll bar exists.  
  
:window-inactive  
//Applicable to all scroll bars, indicating the area containing the scroll bar when the focus is not on the window.  
  
::-webkit-scrollbar-track-piece:start {  
/Scroll bar top or left half/  
}  
  
::-webkit-scrollbar-thumb:window-inactive {  
/When the focus is not in the current area slider state/  
}  
  
::-webkit-scrollbar-button:horizontal:decrement:hover {  
/State when the mouse is on the button below the horizontal scroll bar/  
}

Summarize

This is the end of this article about CSS3 custom scrollbar style::webkit-scrollbar. For more relevant CSS3 custom scrollbar style content, please search 123WORDPRESS.COM’s previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

<<:  Vue.js front-end web page pop-up asynchronous behavior example analysis

>>:  Discussion on the problem of iframe node initialization

Recommend

Analyzing the node event loop and message queue

Table of contents What is async? Why do we need a...

How to implement the prototype pattern in JavaScript

Overview The prototype pattern refers to the type...

Solve the problem that PhpStorm fails to connect to VirtualBox

Problem description: When phpstorm's SFTP hos...

5 ways to migrate Docker containers to other servers

Migration is unavoidable in many cases. Hardware ...

A Preliminary Study on Vue Unit Testing

Table of contents Preface Why introduce unit test...

Vue uses Amap to realize city positioning

This article shares the specific code of Vue usin...

Detailed explanation of several methods of installing software in Linux

1. RPM package installation steps: 1. Find the co...

zabbix custom monitoring nginx status implementation process

Table of contents Zabbix custom monitoring nginx ...

Native JS object-oriented typing game

This article shares the specific code of JS objec...

Solution to Ubuntu not being able to connect to the Internet

Problem description: I used a desktop computer an...

Use CSS to set the width of INPUT in TD

Recently, when I was using C# to make a Web progra...

JavaScript - Using slots in Vue: slot

Table of contents Using slots in Vue: slot Scoped...

Causes and solutions to the garbled character set problem in MySQL database

Preface Sometimes when we view database data, we ...

Detailed explanation of Js class construction and inheritance cases

The definition and inheritance of classes in JS a...