注:本文使用方法仅在以webkit为内核的浏览器生效(谷歌,safari)
代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>滚动条样式</title>
<style>
.scroll{
height: 400px;
width: 400px;
overflow:auto;
margin:0 auto;
margin-top: 100px;
border:1px solid black;
}
.scrollSon{
height: 500px;
}
/*滚动条整体粗细样式*/
::-webkit-scrollbar {
/*高宽分别对应横竖滚动条的尺寸*/
width: 8px;
height: 8px;
}
/*滚动条里面小方块*/
::-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;
}
/*滚动条轨道*/
::-webkit-scrollbar-track {
border-radius: 10px !important;
box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2) !important;
background: #EDEDED !important;
}
.zhanwei{
height: 2000px;
}
</style>
</head>
<body>
<div class="container">
<div class="scroll">
<div class="scrollSon"></div>
</div>
</div>
<div class="zhanwei"></div>
</body>
</html>
效果:
如果只希望修改其中一个元素的滚动条,只需要将元素的选择器加在伪元素选择器之前,并且!important可以去掉。