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
isscroll
, or whenoverflow
isauto
and the box is overflowing. Overlay scrollbars do not consume space. stable
- When using classic scrollbars, the gutter will be present if
overflow
isscroll
orauto
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
isscroll
orauto
, 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
andalways
will also be in effect whenoverflow
isvisible
,hidden
orclip
. Only the gutter will be displayed, not a scrollbar.
Formal definition
Initial value | auto |
---|---|
Applies to | all elements |
Inherited | no |
Computed value | as specified |
Animation type | discrete |
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
Specification | Status | Comment |
---|---|---|
CSS Overflow Module Level 4 The definition of 'scrollbar-gutter' in that specification. | Unknown | Initial definition. |
Browser compatibility
BCD tables only load in the browser
See also
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论