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

此生再无相见时 提交于 2020-01-30 01:12:02

问题


Here are two CSS scroll-snaps examples from csstricks.com

  • Example #0 works on Chrome on Windows
  • Example #3 does not work

Why does one of them work, and not the other; what is the difference between the two?

Example 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;
}

Example 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;
}

回答1:


Because by default the <body> doesn't scroll, <html> does.
Change the selector to :root and it will work in Chrome.

Though to be safe you'd be better defining your own scrolling area since older browsers were indeed using <body> as scrollingElement.



来源:https://stackoverflow.com/questions/58702436/potensial-css-scroll-snap-bug-in-chrome-windows-two-examples-only-one-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!