css设置滚动条宽度::-webkit-scrollbar

4,727 阅读1分钟

在css中使用伪类选择器 ::-webkit-scrollba 和宽度属性 width 来设置滚动条的宽度。

.main::-webkit-scrollbar{ width:宽度值; }

/定义滚动条样式(高宽及背景)/ .main::-webkit-scrollbar { width: 6px; /* 滚动条宽度, width:对应竖滚动条的宽度 height:对应横滚动条的高度*/ height:4px; background: #007acc; }

/定义滚动条轨道(凹槽)样式/ .main::-webkit-scrollbar-track { -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3); /* 较少使用 */ border-radius: 3px; background:rgba(0,0,0,0.1); }

/定义滑块 样式/ .main::-webkit-scrollbar-thumb { border-radius: 3px; height: 100px; /* 滚动条滑块长度 */ -webkit-box-shadow: inset005pxrgba(0,0,0,0.2); background:rgba(0,0,0,0.2); }

image.png