1. div代碼。
<body> <div class="div-box box1"> <div class="div-text"></div> </div> </body>
2. css代碼。
<style> .div-box { width: 600px; height: 200px; overflow-y: auto; border: 1px solid #DCDFE6; margin: 20px; } .box1::-webkit-scrollbar{ height: 20px; width: 20px; } </style>
設置滾動條顏色:
.div-box { width: 600px; height: 200px; overflow-y: auto; border: 1px solid #DCDFE6; margin: 20px;; scrollbar-arrow-color: #000; /*頂部/底部圖標顏色*/ scrollbar-face-color: #333; /*滾動條顏色*/ scrollbar-shadow-color: #999;/*滾動條陰影顏色*/ }
設置滾動條尺寸:
/*定義滾動條高寬及背景 高寬分別對應橫豎滾動條的尺寸*/ .div-box::-webkit-scrollbar{ width: 16px; height: 16px; background-color: #F5F5F5; } /*定義滾動條軌道 內陰影+圓角*/ .div-box::-webkit-scrollbar-track{ -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3); border-radius: 10px; background-color: #F5F5F5; } /*定義滑塊 內陰影+圓角*/ .div-box::-webkit-scrollbar-thumb{ border-radius: 10px; -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,.3); background-color: #555; }
轉載自: https://blog.csdn.net/hanshileiai/article/details/40398177