css自定义滚动条_如何创建CSS技巧自定义滚动条

css自定义滚动条

Chris Coyier of
CSS-Tricks is an amazing engineer and blogger. He's not only creative but has always had the drive to put his thoughts to work, no matter how large. He also has a good eye for the little things that can make CSS-Tricks or your site special. One of those little things is his custom scrollbar -- let's have a look at how it's done!

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自定义滚动条

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值