CSS Chrome (Windows) 中的潜在 CSS 滚动快照错误。两个例子,只有一个作品。为什么?

Potential CSS Scroll Snap bug in Chrome (Windows). Two examples, only one work. Why?

这是来自 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;
}

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

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