scrollbar-width - CSS: Cascading Style Sheets 编辑

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

Initial valueauto
Applies toscrolling boxes
Inheritedno
Computed valueas specified
Animation typediscrete

Syntax

/* Keyword values */
scrollbar-width: auto;
scrollbar-width: thin;
scrollbar-width: none;

/* Global values */
scrollbar-width: inherit;
scrollbar-width: initial;
scrollbar-width: unset;

Values

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

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

Accessibility concerns

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).

Formal definition

Initial valueauto
Applies toscrolling boxes
Inheritedno
Computed valueas specified
Animation typediscrete

Formal syntax

auto | thin | none

Examples

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>

Result

Specifications

SpecificationStatusComment
CSS Scrollbars Level 1
The definition of 'scrollbar-width' in that specification.
Working DraftInitial Definition

Browser compatibility

BCD tables only load in the browser

See also

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:114 次

字数:7306

最后编辑:7 年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文