CSS 滚动条样式修改

211 阅读1分钟

CSS 滚动条样式修改

西红柿炒牛肉

1. 滚动条整体部分

使用 ::-webkit-scrollbar

.container::-webkit-scrollbar {
    width: 20px;//修改滚动条宽度
}

2. 滚动条中的滑块

使用 ::-webkit-scrollbar-thumb

.container::-webkit-scrollbar-thumb {
    border-radius: 8px;
    box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
    background: #666666;
}
//鼠标移入样式
.container::-webkit-scrollbar-thumb:hover {
    background: #333333;
}

3. 滚动条中的外层轨道

使用 ::-webkit-scrollbar-track

.container::-webkit-scrollbar-track {
    border-radius: 8px;
    background: #eeeeee;
}

4. 滚动条中的两端箭头按钮

使用 ::-webkit-scrollbar-button

.container::-webkit-scrollbar-button {
    background: #eeeeee;
}

5. 水平方向和垂直方向滚动条交接处

使用 ::-webkit-scrollbar-corner

.container::-webkit-scrollbar-corner {
    background-color: transparent;
}

6. 单独设置水平方向或垂直方向滚动条样式

水平方向上的滚动条::horizontal 垂直方向上的滚动条::vertical

//水平方向滚动条
.container::-webkit-scrollbar:horizontal {
    width: 10px;
}
//垂直方向滚动条
.container::-webkit-scrollbar:vertical {
    width: 20px;
}

7.示例

.ant-layout-content::-webkit-scrollbar {
    width: 5px;
    height: 10px;
}

.ant-layout-content::-webkit-scrollbar-track {
    border-radius: 10px;
}

.ant-layout-content::-webkit-scrollbar-thumb {
    border-radius: 10px;
    box-shadow: inset 0 0 0 rgba(0, 158, 255, 0.46);
    background-color: rgba(0, 158, 255, 0.46);
}

image-20240104173807701.png