CSS 属性 overscroll-behavior-x 确定浏览器在达到滚动区域的水平边界时执行的操作。
您可以参考 overscroll-behavior 以获取详细信息。
可能的值
CSS 属性 overscroll-behavior-x 被定义为关键字之一,如下所示。
- auto - 默认滚动行为是正常的。
- contain - 滚动行为仅在设置值的元素中可见。不对相邻元素设置滚动。
- none - 未看到滚动链接行为。避免了默认的滚动溢出行为。
适用于
所有未替换的块级元素和未替换的内联块元素。
语法
overscroll-behavior-x = contain | auto | none
CSS overscroll-behavior-x - 包含值
以下示例演示了 overscroll-behavior-x: contain 的用法,该 overscroll-behavior-x: contain 将水平滚动效果设置为包含的和非连续的。
<html>
<head>
<style>
main {
height: 500px;
width: 2000px;
background-color: slateblue;
}
main > div {
height: 300px;
width: 500px;
overflow: auto;
position: relative;
top: 100px;
left: 100px;
overscroll-behavior-x: contain;
}
div > div {
height: 100%;
width: 1500px;
background-color: lightblue;
}
p {
padding: 10px;
background-color: rgba(0, 0, 150, 0.2);
margin: 0;
width: 300px;
position: relative;
top: 10%;
left: 2%;
}
</style>
</head>
<body>
<h1>overscroll-behavior-x Property</h1>
<main>
<div>
<div>
<p>
<b>overscroll-behavior-x</b> defines the horizontal scrolling area behavior.
The value contain prevents the parent element getting scrolled. Thus preventing the
scrolling chain experience.
</p>
</div>
</div>
</main>
</body>
</html>
CSS overscroll-behavior-x - 自动值
以下示例演示了 overscroll-behavior-x: auto 的用法,该 auto 将滚动效果设置为默认值,其中浏览器决定在到达应用它的元素的边界时滚动父元素。
<html>
<head>
<style>
main {
height: 500px;
width: 2000px;
background-color: slateblue;
}
main > div {
height: 300px;
width: 500px;
overflow: auto;
position: relative;
top: 100px;
left: 100px;
overscroll-behavior-x: auto;
}
div > div {
height: 100%;
width: 1500px;
background-color: lightblue;
}
p {
padding: 10px;
background-color: rgba(0, 0, 150, 0.2);
margin: 0;
width: 300px;
position: relative;
top: 10%;
left: 2%;
}
</style>
</head>
<body>
<h1>overscroll-behavior-x Property</h1>
<main>
<div>
<div>
<p>
<b>overscroll-behavior-x: auto</b> defines the horizontal scrolling area behavior.
The value auto behaves like the normal scrolling behavior. It is the default value.
</p>
</div>
</div>
</main>
</body>
</html>