scrollbar-gutter - CSS: Cascading Style Sheets 编辑

The scrollbar-gutter CSS property allows authors to reserve space for the scrollbar, preventing unwanted layout changes as the content grows while also avoiding unnecessary visuals when scrolling isn't needed.

An element's scrollbar gutter is the space between the inner border edge and the outer padding edge, where the browser may display a scrollbar. If no scrollbar is present, the gutter will be painted as an extension of the padding.

The browser determines whether classic scrollbars or overlay scrollbars are used:

  • Classic scrollbars are always placed in a gutter, consuming space when present.
  • Overlay scrollbars are placed over the content, not in a gutter, and are usually partially transparent.

Syntax

/* Initial value */
scrollbar-gutter: auto;

/* "stable" keyword, with optional modifiers */
scrollbar-gutter: stable;
scrollbar-gutter: stable both;
scrollbar-gutter: stable force;
scrollbar-gutter: stable both force;

/* "always" keyword, with optional modifiers */
scrollbar-gutter: always;
scrollbar-gutter: always both;
scrollbar-gutter: always force;
scrollbar-gutter: always both force;

Values

auto
The initial value. Classic scrollbars create a gutter when overflow is scroll, or when overflow is auto and the box is overflowing. Overlay scrollbars do not consume space.
stable
When using classic scrollbars, the gutter will be present if overflow is scroll or auto even if the box is not overflowing. When using overlay scrollbars, the gutter will not be present.
always
The scrollbar gutter will always be present when overflow is scroll or auto, regardless of the type of scrollbar or of whether the box is overflowing.
both
If a gutter would be present on one of the inline start/end edges of the box, another will be present on the opposite edge as well.
force
The keywords stable and always will also be in effect when overflow is visible, hidden or clip. Only the gutter will be displayed, not a scrollbar.

Formal definition

Initial valueauto
Applies toall elements
Inheritedno
Computed valueas specified
Animation typediscrete

Formal syntax

auto | [ stable | always ] && both? && force?

Examples

Example 1

Prevent layout changes when the content grows or shrinks:

.container {
    scrollbar-gutter: stable;
}

Example 2

Prevent an overlay scrollbar from obscuring content:

.container {
    scrollbar-gutter: always;
}

Example 3

Keep the symmetry between both sides of the box:

.container {
    scrollbar-gutter: stable both;
}

Example 4

Reserve the same amount of space on the edges of an element that is adjacent to a scrolling element as is being reserved in the latter, so that both line up visually:

.header {
    scrollbar-gutter: always force;
}

.container {
    scrollbar-gutter: always;
}

Specifications

SpecificationStatusComment
CSS Overflow Module Level 4
The definition of 'scrollbar-gutter' in that specification.
UnknownInitial definition.

Browser compatibility

BCD tables only load in the browser

See also

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

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

发布评论

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

词条统计

浏览:30 次

字数:6928

最后编辑:7 年前

编辑次数:0 次

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