CSS Scrollbars

Experimental

这是一个实验中的功能
此功能某些浏览器尚在开发中,请参考浏览器兼容性表格以得到在不同浏览器中适合使用的前缀。由于该功能对应的标准文档可能被重新修订,所以在未来版本的浏览器中该功能的语法和行为可能随之改变。

CSS Scrollbars标准化了由ie5引入的废弃的滚动条颜色属性

基础例子

在这个例子里 我们选择使用一个比较细的 滚动轨道为绿色,滚动块为紫色的滚动条

.scroller {
  width: 300px;
  height: 100px;
  overflow-y: scroll;
  scrollbar-color: rebeccapurple green;
  scrollbar-width: thin;
}

HTML

<div class="scroller">
Veggies es bonus vobis, proinde vos postulo essum magis kohlrabi
welsh onion daikon amaranth tatsoi tomatillo melon azuki bean garlic.
Gumbo beet greens corn soko endive gumbo gourd. Parsley shallot courgette
tatsoi pea sprouts fava bean collard greens dandelion okra wakame tomato.
Dandelion cucumber earthnut pea peanut soko zucchini.
</div>

Result

Reference

CSS Properties

Specifications

Specification Status Comment
CSS Scrollbars Level 1 Working Draft Initial definition.

Accessibility concerns

When you customize scrollbars, consider they have enough contrast and that their hit area is large enough for people who use touch input.

Browser compatibility

scrollbar-width

BCD tables only load in the browser

scrollbar-color

BCD tables only load in the browser