CSS Scroll Snap
CSS Scroll Snap snaps the scrolling of content to predefined points in the container. Again, it is a user interface pattern that is commonplace in the interfaces of native applications, app stores, and things like carousels, but historically required JavaScript to implement.
There have been different implementations and names for CSS Scroll Snap in browsers since 2014. However, it's taken time for a stable specification to emerge, along with compatible implementations. You can read the official specification at https://www.w3.org/TR/css-scroll-snap-1/.
Let's use CSS Scroll Snap to add scroll snap functionality to our horizontal "top-grossing films of 2014" container.
The scroll-snap-type property
First of all, we define the scroll-snap-type
for our scrolling container. This is where we can decide whether we want the container to scroll snap in the x
, y
, or both
, axes.
This property also allows us to define the...