📜 ⬆️ ⬇️

WebKit learned to stylize scrollbars


The news a week ago passed unnoticed that the latest builds of WebKit added the ability to override the appearance of the scrollbars in all elements where they can be found:


Innovation has not yet been implemented in other engines (which may reduce its prevalence to zero), but nevertheless, I am sure it will work for the common good, setting a good example to follow and helping developers not to sit still. Below is a translation of the original publication .


A sign that defines the styling of scroll bars is the pseudo-class scrollbar. If specified, WebKit, instead of standard controls, will use the information specified in CSS.
')
:: - webkit-scrollbar {
width: 13px;
height: 13px;
}

The width and height properties specify, respectively, the width of the vertical and the height of the horizontal scrollbar. Values ​​can also be set in percent, then pixel values ​​will be calculated, as usual, based on the size of the parent element.

Scrollbar consists of a bar and scroll buttons. The strip, in turn, consists of a floating button and two empty areas around it. In addition to styling the scrollbars themselves, you can also set styles for an empty “corner” in the place where the vertical and horizontal scrollbars are closed. Moreover, it is possible to stylize the “resizer” in TEXTAREA. Here is the complete list of new pseudo-elements:



Each of these objects can be styled to define borders, shadows, background images, and so on, thus creating fully custom scrollbars. At the same time, they will preserve the behavior in accordance with the OS settings (such as the position of the scroll buttons and the response to clicks). The following pseudo-classes can be applied to pseudo-elements:



In addition to all of the above, the selectors also work with the scrollbar elements: enabled,: disabled,: hover and: active. To hide some elements, they can set the display property: none

Scrollbars can also set margins, including negative ones. Thus, for example, overlapping scroll buttons is implemented.

If you are using a fresh build of WebKit, then in this example you can see fancy scrollbars that implement both MacOS X features (dual buttons, inactivity, button overlapping, etc.) and Windows Vista (pointing effect, appearance when you click on the bar scrolling, etc.).

Source: https://habr.com/ru/post/55550/


All Articles