Home Web Front-end CSS Tutorial CSS example code for setting scroll bar style

CSS example code for setting scroll bar style

Jul 12, 2018 pm 02:50 PM
css

This article mainly introduces the example code of CSS setting scroll bar style. It is very good and has certain reference value. Friends who need it can refer to it

The implementation code of CSS setting scroll bar style is as follows Representation:

•::-webkit-scrollbar The whole part of the scroll bar
•::-webkit-scrollbar-thumb The small square inside the scroll bar can move up and down (or left and 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 track of the scroll bar Buttons at both ends allow fine-tuning the position of the small squares by clicking on them.
•::-webkit-scrollbar-track-piece The inner track, the middle part of the scroll bar (removed)
•::-webkit-scrollbar-corner The corner, that is, the intersection of the two scroll bars
•::-webkit-resizer A small control at the intersection of two scroll bars for resizing elements by dragging

/*定义滚动条高宽及背景 高宽分别对应横竖滚动条的尺寸*/
::-webkit-scrollbar
{
    width: 16px;
    height: 16px;
    background-color: #F5F5F5;
}
/*定义滚动条轨道 内阴影+圆角*/
::-webkit-scrollbar-track
{
    -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3);
    border-radius: 10px;
    background-color: #F5F5F5;
}
/*定义滑块 内阴影+圆角*/
::-webkit-scrollbar-thumb
{
    border-radius: 10px;
    -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,.3);
    background-color: #555;
}
Copy after login

Details Setting

To define scroll bars is to use pseudo-elements and pseudo-classes. So what are pseudo-elements and pseudo-classes?

Everyone should be familiar with pseudo-classes: link, :focus, :hover. In addition, many pseudo-class selectors have been added to CSS3, such as :nth-child, :last-child, :nth-last-of -type() etc.

You have seen the pseudo elements in CSS before: :first-line, :first-letter, :before, :after. Then in CSS3, the pseudo-element has been adjusted, and a ":" has been added to the previous one, which is now "::first-letter,::first-line,::before,::after", In addition, CSS3 also adds a "::selection". Two "::" and one ":" are mainly used in CSS3 to distinguish pseudo-classes and pseudo-elements.

Webkit’s implementation of pseudo-classes and pseudo-elements is very strong. You can define the scroll bar as a page element, and then combine it with some advanced CSS3 attributes, such as gradients, rounded corners, RGBa, etc. Then if you need to use images in some places, you can also convert the images to Base64, otherwise you have to load multiple images every time and increase the number of requests.

Any object can be set: borders, shadows, background images, etc. The created scroll bar will still complete its interactive behavior according to the settings of the operating system itself. The following pseudo-classes can be applied to the above pseudo-elements. It's a bit complicated. For details on how to write it, you can see the first demo. There are also comments there.

:horizontal
//horizontal伪类适用于任何水平方向上的滚动条
:vertical
//vertical伪类适用于任何垂直方向的滚动条
:decrement
//decrement伪类适用于按钮和轨道碎片。表示递减的按钮或轨道碎片,例如可以使区域向上或者向右移动的区域和按钮
:increment
//increment伪类适用于按钮和轨道碎片。表示递增的按钮或轨道碎片,例如可以使区域向下或者向左移动的区域和按钮
:start
//start伪类适用于按钮和轨道碎片。表示对象(按钮 轨道碎片)是否放在滑块的前面
:end
//end伪类适用于按钮和轨道碎片。表示对象(按钮 轨道碎片)是否放在滑块的后面
:double-button
//double-button伪类适用于按钮和轨道碎片。判断轨道结束的位置是否是一对按钮。也就是轨道碎片紧挨着一对在一起的按钮。
:single-button
//single-button伪类适用于按钮和轨道碎片。判断轨道结束的位置是否是一个按钮。也就是轨道碎片紧挨着一个单独的按钮。
:no-button
no-button伪类表示轨道结束的位置没有按钮。
:corner-present
//corner-present伪类表示滚动条的角落是否存在。
:window-inactive
//适用于所有滚动条,表示包含滚动条的区域,焦点不在该窗口的时候。
::-webkit-scrollbar-track-piece:start {
/*滚动条上半边或左半边*/
}
::-webkit-scrollbar-thumb:window-inactive {
/*当焦点不在当前区域滑块的状态*/
}
::-webkit-scrollbar-button:horizontal:decrement:hover {
/*当鼠标在水平滚动条下面的按钮上的状态*/
}
Copy after login

The above is the detailed content of CSS example code for setting scroll bar style. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Two Point Museum: All Exhibits And Where To Find Them
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to set unknown attributes in vscode vscode method to set unknown attributes How to set unknown attributes in vscode vscode method to set unknown attributes May 09, 2024 pm 02:43 PM

1. First, open the settings icon in the lower left corner and click the settings option. 2. Then, find the CSS column in the jumped window. 3. Finally, change the drop-down option in the unknownproperties menu to the error button.

Graphical steps for setting the default properties of CSS in Visual Studio 2019 Graphical steps for setting the default properties of CSS in Visual Studio 2019 May 09, 2024 pm 02:01 PM

1. Open Visual Studio 2019, find its option settings, and click CSS. 2. Here you can see the technical settings of the following attributes. 3. Now you can set text and fill borders here. 4. At this time, you can also set the floating positioning here. 5. At this moment, you can also set the border and background here to complete the operation. 6. Finally, click the OK button here to set the CSS default properties.

How to isolate styles in components in vue How to isolate styles in components in vue May 09, 2024 pm 03:57 PM

Style isolation in Vue components can be achieved in four ways: Use scoped styles to create isolated scopes. Use CSS Modules to generate CSS files with unique class names. Organize class names using BEM conventions to maintain modularity and reusability. In rare cases, it is possible to inject styles directly into the component, but this is not recommended.

The difference between v-show and v-if in vue The difference between v-show and v-if in vue May 09, 2024 pm 01:48 PM

The main difference between v-show and v-if in Vue is: v-show: controls the display of elements by changing the display style attribute. It is lightweight and performance-friendly for elements that frequently switch to display/hide; but it will retain the space occupied by the elements. , may cause flickering. v-if: Insert or delete elements through conditions, affecting the layout flow and avoiding flickering; however, the cost of destroying and re-creating elements is high, and it is not suitable for frequently switching displayed/hidden elements.

How to register for Bitstamp exchange pro? Is it safe? Is it formal? How to register for Bitstamp exchange pro? Is it safe? Is it formal? Aug 13, 2024 pm 06:36 PM

How to register BitstampPro? Visit the BitstampPro website. Fill in your personal information and email address. Create a password and accept the terms. Verify email address. Is BitstampPro safe? Authentication required. Enforce the use of two-factor authentication. Most assets are stored in cold storage. Use HTTPS to encrypt communication. Conduct regular security audits. Is BitstampPro legitimate? Registered in Luxembourg. Regulated by the Luxembourg Financial Supervisory Committee. Comply with anti-money laundering and know-your-customer regulations.

How to implement the custom table function of clicking to add data in dcat admin? How to implement the custom table function of clicking to add data in dcat admin? Apr 01, 2025 am 07:09 AM

How to implement the table function of custom click to add data in dcatadmin (laravel-admin) When using dcat...

The latest ranking list of virtual currency trading platform APP (inventory of top 10 virtual currency trading platforms) The latest ranking list of virtual currency trading platform APP (inventory of top 10 virtual currency trading platforms) Mar 04, 2025 pm 03:51 PM

This article lists the top ten leading cryptocurrency exchanges in the world, including OKX, Binance, Gate.io, Huobi, Kraken, Coinbase, KuCoin, Crypto.com, Bitfinex and Bitstamp. With their strong technical strength, rich product lines, strict compliance operations and innovative ecological construction, these exchanges have taken the lead in the global cryptocurrency market. The article will introduce their special functions, technical architecture, security measures, compliance qualifications and ecosystem construction respectively, providing reference for investors to choose a suitable trading platform.

What is the format of the source file? What is the format of the source file? May 09, 2024 pm 10:51 PM

Source files are uncompiled files containing original code or data, and their formats vary between programming languages ​​and applications. Common formats include text files (.txt, .csv), programming languages ​​(such as .py, .java), markup languages ​​(such as .html, .css), image files (such as .png, .jpg), video files (such as .mp4, .avi), and other formats such as JSON (.json), PDF (.pdf), Word document (.doc), etc.

See all articles