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>
结果
Reference
CSS Properties
规范
Specification |
---|
CSS Scrollbars Styling Module Level 1 # scrollbar-width |
CSS Scrollbars Styling Module Level 1 # scrollbar-color |
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.
浏览器兼容性
css.properties.scrollbar-width
BCD tables only load in the browser
css.properties.scrollbar-color
BCD tables only load in the browser