自定义滚动条

130 阅读1分钟

一、使用浏览器滚动条,自定义样式覆盖

若要单独定义,前面加前缀即可,如html

/*滚动条整体粗细样式*/
html::-webkit-scrollbar {
    /*高宽分别对应横竖滚动条的尺寸*/
    width: 8px;
    height: 8px;
}

/*滚动条里面小方块*/
html::-webkit-scrollbar-thumb {
    border-radius: 10px !important;
    box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2) !important;
    /* 颜色 */
    /* background:#b6b6b6!important; */
    /* 线性渐变背景 */
    background-image: linear-gradient(45deg, #ffbd61 25%,#ffbd61 25%, #ff8800 25%, #ff8800 50%,#ffbd61 50%, #ffbd61 75%, #ff8800 75%, #ff8800 100%)!important;
}

/*滚动条轨道*/
html::-webkit-scrollbar-track {
    border-radius: 10px !important;
    box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2) !important;
    background: #EDEDED !important;
}

如果希望滚动条不占用容器宽度,可以使用overflow:overlay

二、隐藏浏览器滚动条,自定义滚动条

1、react-custom-scrollbars

2、react-scroll

3、react-scroll-parallax

4、better-scroll

参考:

CSS设置滚动条样式

CSS-滚动条样式设置