css滾動條樣式自定義

很簡單的幾行代碼html

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
  <style>
    * {
      margin: 0;
      padding: 0;
    }
    .out {
      width: 600px;
      height: 600px;
      margin: 100px auto;
      overflow-y: auto;
    }
    /* 滾動條總體樣式(高寬分別對應橫豎滾動條的尺寸) */
    .out::-webkit-scrollbar {
      width: 5px;
      height: 5px;
    }
    /* 滾動條裏面小方塊 */
    .out::-webkit-scrollbar-thumb {
      border-radius: 5px;
      -webkit-box-shadow: inset 0 0 5px rgba(0,0,0,0.2);
      background: rgba(0,0,0,0.2);
    }
    /* 滾動條裏面軌道 */
    .out::-webkit-scrollbar-track {
      -webkit-box-shadow: inset 0 0 5px rgba(0,0,0,0.2);
      border-radius: 0;
      background: rgba(0,0,0,0.1);
    }
  </style>
</head>
<body>
  <div class="out">
    <p style="height:250px;background: #ccc;">段落一</p>
    <p style="height:250px;background: #eee;">段落二</p>
    <p style="height:250px;background: #ccc;">段落三</p>
  </div>
</body>
</html>

最終效果圖:web

相關文章
相關標籤/搜索