How do you use CSS to change the page scrollbar completely?
The default browser scrollbar is usually grey and operates in different operating systems (e. g. Windows and The performance of the MacOS is very different. For developers who are seeking a very visual experience, it is a very important task to be able to learn from the experience. Custom Scrollbar It's compulsory. This tool is specific to the Webkit kernel browser (Chrome, Safari, new edition) Edge's code gives you perfect control over every pixel in the scrollbar.
1. Core components of the Webkit scrollbar
To be fully customized, you need to understand the following three main hypocritical elements:
-
::-webkit-scrollbar: The packaging of the entire scrollbar, which can be set at width or height. -
::-webkit-scrollbar-track: Track of scrollbar (background area). -
::-webkit-scrollbar-thumb: Slider on the scrollbar, the user drags.
2. Addressing common questions: Why is my scrollbar style not working?
When using custom scrollbar codes, developers often encounter the following problems:
-
Browser compatibility:
::-webkit-scrollbarOnly effective at Webkit/Blink kernel. For Firefox, you need to use it.scrollbar-widthandscrollbar-color。 This tool generates primarily Webkit styles, as it provides a more robust customization (e.g. round angles and shadows). -
Level issues:
Make sure your CSS selector is sufficiently high or directly applied across the board.
htmlorbodyGo on. - Movement-end performance: In many mobile-end browsers, the scrollbar default is hidden or is taken over by the system, and the custom style may not be shown.
3. Interactive design recommendations
When designing scrollbars, follow the following UX principles:
- Contrast: Ensure that the contrast of sliders with orbits is sufficiently high to allow for rapid user positioning.
- Medium width: Scroll bars are too narrow (e.g. less than 6px) to cause difficulties in clicking; The idea is that the space is too wide to be used to capture valuable page content.
-
Visual feedback:
Could consider adding
:hover, change the colour of the slider when the user is hovering.
4. Progress: How to support Firefox?
Although Firefox has limited customization capacity, you can add the following basic codes to be consistent:
* {
scrollbar-width: thin;
scrollbar-color: #7fbf4a #1a1a24;
}
Replace the above colour with the slider and orbital colours that you designed.