brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: scroll-snap-type makes a css carousel stop on each card without JavaScript

Css
~/tips/tip-css-scroll-snap-carousel

.row { display: flex; gap: 1rem; overflow-x: auto; scroll-snap-type: x mandatory; }

Makes a horizontally scrolling row stop neatly on each item as you swipe.

A swipeable row that snaps to its items needs three lines of CSS, not a slider library.

.row { display: flex; gap: 1rem; overflow-x: auto; scroll-snap-type: x mandatory; }
.row > * { flex: 0 0 80%; scroll-snap-align: start; }

scroll-snap-type on the scroll container picks the axis and strictness, and scroll-snap-align on the children says where each one should rest. With mandatory the row always settles on an item. With proximity the browser decides whether to snap, which feels gentler on content that people read while scrolling. Add scroll-padding-inline on the container when a fixed element covers the edge.

Further reading: MDN: scroll-snap-type

More Css tips CSS Overview in Chrome DevTools audits the colors and fonts of a page .notice:empty { .toast { article { counter-reset: h2; } .toolbar { All Css tips (66) All topics

Link