This example implements something very similar to the interactive example above, except that here we'll explain to you how it's implemented.
The aim here is to create four horizontally-scrolling blocks, the second and third of which snap into place, near but not quite at the left of each block.
HTML
The HTML includes a scroller with four children:
CSS
Let's walk through the CSS. The outer container is styled like this:
The main parts relevant to the scroll snapping are overflow-x: scroll, which makes sure the contents will scroll and not be hidden, and scroll-snap-type: x mandatory, which dictates that scroll snapping must occur along the horizontal axis, and the scrolling will always come to rest on a snap point.
The child elements are styled as follows:
The most relevant part here is scroll-snap-align: start, which specifies that the left-hand edges (the "starts" along the x axis, in our case) are the designated snap points.
Last of all we specify the scroll margin-values, a different one for the second and third child elements:
This means that when scrolling past the middle child elements, the scrolling will snap to 1rem outside the left edge of the second <div>, and 2rems outside the left edge of the third <div>.
Note: Here we are setting scroll-margin on all sides at once, but only the start edge is really relevant. It would work just as well here to only set a scroll margin on that one edge, for example with scroll-margin-inline-start: 1rem, or scroll-margin: 0 0 0 1rem.
Result
Try it for yourself: