css自定义滚动条
CSS-Tricks的 Chris Coyier是一位了不起的工程师和博客。 无论他有多大,他不仅富有创造力,而且总是有驱使思想付诸实践的动力。 对于使CSS-Tricks或您的网站与众不同的小事情,他也很有见识。 这些小事情之一是他的自定义滚动条-让我们看看它是如何完成的!
To create this excellent scrollbar effect, you'll need to employ three CSS selectors and the styling of your choosing:
要创建出色的滚动条效果,您需要使用三个CSS选择器和您选择的样式:
/* Sets the dimensions of the entire scrollbar */
html::-webkit-scrollbar {
width: 30px;
height: 30px;
}
/* The grabbable scrollbar button */
html::-webkit-scrollbar-thumb {
background: -webkit-gradient(linear,left top,left bottom,from(#ff8a00),to(#e52e71));
background: linear-gradient(180deg,#ff8a00,#e52e71);
border-radius: 30px;
box-shadow: inset 2px 2px 2px hsla(0,0%,100%,.25), inset -2px -2px 2px rgba(0,0,0,.25);
}
/* The vertical scrollbar background */
html::-webkit-scrollbar-track {
background: linear-gradient(90deg,#201c29,#201c29 1px,#100e17 0,#100e17);
}
A few important notes: obviously you can create your own gradient colors but, more importantly, this scrollbar works only in Chrome, Safari, and Edge.
一些重要的注意事项:很明显,您可以创建自己的渐变颜色,但更重要的是,此滚动条仅在Chrome,Safari和Edge中有效。
You need to be careful with these types of small customizations. When done well, they add to your branding and design. When done poorly, you confuse your user. Happy styling!
您需要小心使用这些类型的小型定制。 如果做得好,它们会增加您的品牌和设计。 如果做得不好,您会迷惑您的用户。 造型愉快!
翻译自: https://davidwalsh.name/how-to-create-a-css-tricks-custom-scrollbar
css自定义滚动条