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 |
瀏覽器相容性
載入中…