javascript – 如何更改滚动条拇指的高度?

有没有办法将滚动条的高度更改为固定高度并更改相应滚动的内容量?这是我目前的css代码.

  ::-webkit-scrollbar {
    width: 30px;
}

/* Track */
::-webkit-scrollbar-track {
    box-shadow: inset 0 0 5px #003B7C; 
    border-radius: 10px;
    background: white;
    border-left: 8px solid rgba(255,255,255,0);
    border-right: 8px solid rgba(255,255,255,0);
    background-clip: content-box;
}

/* Handle */
::-webkit-scrollbar-thumb {
    background: linear-gradient(to right,#003B7C, #00538B, #83BBE6); 
    border-radius: 8px;
}

最佳答案 滚动条高度不是“:: – webkit-scrollbar”,而是关于内容高度.您必须为您的内容指定“max-height”和“overflow-y”.您无法为垂直滚动条定义高度.这取决于内容大小.

假设你有这样的事情:

<div class="wrapper">
  <p>Lorem ipsum dolor sit amet consectetur, adipisicing elit. Repellat adipisci itaque beatae quisquam corporis. Eos praesentium temporibus autem assumenda enim aspernatur culpa, esse quam, optio, molestias dolor sapiente vel deserunt!</p>
  <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Impedit provident illo placeat nemo sint dolores quod temporibus, doloremque repudiandae, cum architecto, nostrum aut ipsum atque. Aspernatur autem error unde praesentium!</p>
</div>

如果你这样写CSS:

.wrapper {
    width: 300px;
    max-height: 200px;
    overflow-y: scroll;
}

你可以指定高度.

看这codepen.

点赞