diff --git a/index.html b/index.html index 623738b5c..c638e8e48 100644 --- a/index.html +++ b/index.html @@ -1333,4 +1333,4 @@ var y = e.pageY - btn.offsetTop - btn.offsetParent.offsetTop - + \ No newline at end of file diff --git a/snippets/custom-scrollbar.md b/snippets/custom-scrollbar.md new file mode 100644 index 000000000..b63cc00ae --- /dev/null +++ b/snippets/custom-scrollbar.md @@ -0,0 +1,82 @@ +### Custom scrollbar + +Customizes the scrollbar style for the document and elements with scrollable overflow, on WebKit platforms. + +#### HTML + +```html +
+

Lorem ipsum dolor sit amet consectetur adipisicing elit. Iure id exercitationem nulla qui repellat laborum vitae, molestias tempora velit natus. Quas, assumenda nisi. Quisquam enim qui iure, consequatur velit sit?

+
+``` + +#### CSS + +```css +/* Document scrollbar */ +::-webkit-scrollbar { + width: 8px; +} + +::-webkit-scrollbar-track { + box-shadow: inset 0 0 6px rgba(0,0,0,0.3); + border-radius: 10px; +} + +::-webkit-scrollbar-thumb { + border-radius: 10px; + box-shadow: inset 0 0 6px rgba(0,0,0,0.5); +} + +/* Scrollable element */ +.some-element::webkit-scrollbar { +} +``` + +#### Demo + +
+
+

+ Lorem ipsum dolor sit amet consectetur adipisicing elit. Iure id exercitationem nulla qui repellat laborum vitae, molestias tempora velit natus. Quas, assumenda nisi. Quisquam enim qui iure, consequatur velit sit? +

+

+ Lorem ipsum dolor sit amet consectetur adipisicing elit. Iure id exercitationem nulla qui repellat laborum vitae, molestias tempora velit natus. Quas, assumenda nisi. Quisquam enim qui iure, consequatur velit sit? +

+
+
+ + + +#### Explanation + +1. `::-webkit-scrollbar` targets the whole scrollbar element. +2. `::-webkit-scrollbar-track` targets only the scrollbar track. +3. `::-webkit-scrollbar-thumb` targets the scrollbar thumb. + +There are many other pseudo-elements that you can use to style scrollbars. For more info, visit the [WebKit Blog](https://webkit.org/blog/363/styling-scrollbars/) + +#### Browser support + +⚠️ Scrollbar styling doesn't appear to be on any standards track. + +* https://caniuse.com/#feat=css-scrollbar