I'm trying to have a web page scroll and snap to beginning of some elements as the user scrolls through a webpage using scroll-snap-type: y mandatory
and scroll-snap-align: start
. My problem is that it's a large webpage and unlike many samples where the whole page is just a div and children, I've got many divs and children. If I restrict my divs' direct container to have 100vh the scroll snapping works but there is double scrollable content problem: the document scrolls and the inner div's snapping content scrolls independently of the whole document. If I don't restrict the direct parent's height then snapping doesn't work.
Here is an example: https://codepen.io/canp/pen/abGJKXX
Basically the example in the above link does snap but there is the double scroll problem. I want the outer
class div the only scrolling component, while still snapping to mid
's children page
divs without double scrollbars.
How can I make document scrolling to snap to a grand-grandchild's start position?
It is not entirely clear what your detailed objective is, but the code provided below satisfies the following requirements:
The CSS is straight out of the box from https://www.w3.org/TR/css-scroll-snap/, so should work universally in any browser that supports snapping.
The thing to do is to have no (other) scrolling defined between the level you have the scroll container at and the elements you want to snap.