Chrome(Windows)中的Potensial CSS Scroll Snap错误。两个例子,只有一个工作。为什么?

这是csstricks.com的两个CSS滚动快照示例

为什么其中一个有效,而另一个无效?两者有什么区别?

示例1:

.container {
    flex-basis: 50%;
    max-height: 100vh;
    overflow-y: scroll;
    border: 1px solid gray;
    scroll-snap-type: y mandatory;
    &.proximity {
            scroll-snap-type: y proximity;
    }
}

li {
    border-bottom: 1px solid white;
    padding: 3rem;
    font-size: 1.4rem;
    color: rgba(white,.5);
    background: lightgray;
    text-align: center;
    scroll-snap-align: start;
    display: flex;
    flex-flow: column;
    justify-content: center;
}

示例2:

body {
    font-family: sans-serif;
    scroll-snap-type: mandatory;
    scroll-snap-points-y: repeat(100vh);
    scroll-snap-type: y mandatory;
}
section {
    border-bottom: 1px solid white;
    padding: 1rem;
    height: 100vh;
    scroll-snap-align: start;
    text-align: center;
    position: relative;
}
kirecetycike 回答:Chrome(Windows)中的Potensial CSS Scroll Snap错误。两个例子,只有一个工作。为什么?

由于默认情况下<body>不会滚动,<html>会滚动。
 将选择器更改为:root,它将在Chrome中运行。

为了安全起见,最好定义自己的滚动区域,因为较旧的浏览器确实使用<body>作为scrollingElement

本文链接:https://www.f2er.com/3163172.html

大家都在问