1.布局-Overscroll Behavior
overscroll behavior
用于控制浏览器到达滚动区域边界时的行为的功能类。这个属性可以用来防止在有多个滚动区域的页面中出现不必要的滚动。
1.1 快速参考
Class | Properties |
---|---|
overscroll-auto | overscroll-behavior: auto; |
overscroll-contain | overscroll-behavior: contain; |
overscroll-none | overscroll-behavior: none; |
overscroll-y-auto | overscroll-behavior-y: auto; |
overscroll-y-contain | overscroll-behavior-y: contain; |
overscroll-y-none | overscroll-behavior-y: none; |
overscroll-x-auto | overscroll-behavior-x: auto; |
overscroll-x-contain | overscroll-behavior-x: contain; |
overscroll-x-none | overscroll-behavior-x: none; |
1.2 基本用法
1.2.1 阻止父元素的过度滚动
overscroll-auto
说明:它用于将滚动行为设置为默认。即使到达元素的边界,整个页面也会连同元素一起滚动。它是默认值。
overscroll-contain
说明:用来设置滚动行为,只对所使用的元素进行默认。在元素到达边界后进一步滚动,不会滚动它后面的元素。在相邻的滚动区域不会发生滚动链。
<html lang="en">
<head>
<link rel="stylesheet" href="../dist/output.css" />
</head>
<body class="text-center">
<h1 class="text-green-500 text-5xl font-bold">Tailwind CSS overscroll-behavior</h1>
<b>Tailwind CSS overscroll-auto and overscroll-contain Class</b>
<div class="flex">
<div
class="bg-green-500 mx-24 p-4 w-1/3 h-16 overscroll-contain overflow-y-auto text-justify"
>
Well, let me tell you something, funny boy. Y'know that little stamp, the one that says "New
York Public Library"? Well that may not mean anything to you, but that means a lot to me.
One whole hell of a lot.
</div>
<div class="bg-pink-500 p-2 w-1/4 h-24 overscroll-auto overflow-y-auto">
Sure, go ahead, laugh if you want to. I've seen your type before: Flashy, making the scene,
flaunting convention. Yeah, I know what you're thinking. What's this guy making such a big
stink about old library books? Well, let me give you a hint, junior.
</div>
</div>
<div class="h-[2000px]"></div>
</body>
</html>
- 左边的
div元素
设置了overscroll-contain
,即使滚动到底,只要在这个元素滚动就不会影响父元素的滚动条。 - 右边的
div元素
设置overscroll-contain</