scrollbar-width property allows the author to set the maximum thickness of an element’s scrollbars when they are shown.

初始值 auto
适用于 scrolling boxes
继承 no
计算值 如指定
动画类型 discrete

句法

/* Keyword values */
scrollbar-width: auto;
scrollbar-width: thin;
scrollbar-width: none;
/* Global values */
scrollbar-width: inherit;
scrollbar-width: initial;
scrollbar-width: unset;
					

<scrollbar-width>
Defines the width of the scrollbar as a keyword. It must be one of the following values:
auto The default scrollbar width for the platform.
thin A thin scrollbar width variant on platforms that provide that option, or a thinner scrollbar than the default platform scrollbar width.
none No scrollbar shown, however the element will still be scrollable.

注意 : User Agents must apply any scrollbar-width value set on the root element to the viewport.

可访问性关注

Use this property with caution — setting scrollbar-width to thin or none can make content hard or impossible to scroll if the author does not provide an alternative scrolling mechanism. While swiping gestures or mouse wheels can enable scrolling on such content, some devices have no scroll alternative.

WCAG criterion 2.1.1 (Keyboard) has been in place for a long time to advise on basic keyboard accessibility, and this should include scrolling of content areas. And introduced in WCAG 2.1, criterion 2.5.5 (Target Size) advises that touch targets should be at least 44px in width and height (although the problem is compounded on high-resolution screens; thorough testing is advised).

形式定义

初始值 auto
适用于 scrolling boxes
继承 no
计算值 如指定
动画类型 discrete

形式句法

auto | thin | none
					

范例

Sizing overflow scrollbars

CSS

.scroller {
  width: 300px;
  height: 100px;
  overflow-y: scroll;
  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>
					

结果

规范

规范 状态 注释
CSS Scrollbars Level 1
The definition of 'scrollbar-width' in that specification.
工作草案 Initial Definition

浏览器兼容性

The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
scrollbar-width Chrome 不支持 No Edge 不支持 No Firefox 完整支持 64
完整支持 64
完整支持 63 Disabled
Disabled ). To change preferences in Firefox, visit
IE 不支持 No Opera 不支持 No Safari 不支持 No WebView Android 不支持 No Chrome Android 不支持 No Firefox Android 完整支持 64
完整支持 64
完整支持 63 Disabled
Disabled ). To change preferences in Firefox, visit
Opera Android 不支持 No Safari iOS 不支持 No Samsung Internet Android 不支持 No

图例

完整支持

完整支持

不支持

不支持

用户必须明确启用此特征。

用户必须明确启用此特征。

另请参阅

元数据

  • 最后修改: