overscroll-behavior-inline
overscroll-behavior-inline CSS 属性用于设置当滚动区域的内联方向边界达到时,浏览器的行为。
有关完整说明,请参阅 overscroll-behavior。
语法
css
/* Keyword values */
overscroll-behavior-inline: auto; /* default */
overscroll-behavior-inline: contain;
overscroll-behavior-inline: none;
/* Global values */
overscroll-behavior-inline: inherit;
overscroll-behavior-inline: initial;
overscroll-behavior-inline: revert;
overscroll-behavior-inline: revert-layer;
overscroll-behavior-inline: unset;
overscroll-behavior-inline 属性通过从以下值列表中选择一个关键字来指定。
值
正式定义
正式语法
overscroll-behavior-inline =
contain |
none |
auto
示例
阻止内联方向的过量滚动
在此演示中,我们有两个块级盒子,一个在另一个里面。外层盒子设置了较大的 width,因此页面会水平滚动。内层盒子设置了较小的宽度(和 height),因此它舒适地位于视口内,但其内容被赋予了较大的宽度,因此它也会水平滚动。
默认情况下,当内层盒子滚动并达到滚动边界时,整个页面将开始滚动,这可能不是我们想要的结果。为了避免在内联方向发生这种情况,我们在内层盒子上设置了 overscroll-behavior-inline: contain。
HTML
html
<main>
<div>
<div>
<p>
<code>overscroll-behavior-inline</code> has been used to make it so that
when the scroll boundaries of the yellow inner box are reached, the
whole page does not begin to scroll.
</p>
</div>
</div>
</main>
CSS
css
main {
height: 400px;
width: 3000px;
background-color: white;
background-image: repeating-linear-gradient(
to right,
transparent 0px,
transparent 19px,
rgb(0 0 0 / 50%) 20px
);
}
main > div {
height: 300px;
width: 400px;
overflow: auto;
position: relative;
top: 50px;
left: 50px;
overscroll-behavior-inline: contain;
}
div > div {
height: 100%;
width: 1500px;
background-color: yellow;
background-image: repeating-linear-gradient(
to right,
transparent 0px,
transparent 19px,
rgb(0 0 0 / 50%) 20px
);
}
p {
padding: 10px;
background-color: rgb(255 0 0 / 50%);
margin: 0;
width: 360px;
position: relative;
top: 10px;
left: 10px;
}
结果
规范
| 规范 |
|---|
| CSS Overscroll Behavior Module Level 1 # overscroll-behavior-longhands-logical |
浏览器兼容性
加载中…