9.1 · Layout
Masonry in CSS: grid lanes
Masonry layout as a display type, with no JavaScript.
display: grid-lanes lays items into columns and places
each one in whichever lane is currently shortest. That’s the
Pinterest-style masonry layout, with no JavaScript and no gaps under
short items.
You define the lanes with grid-template-columns as usual.
Support is still arriving and the spec has changed names along the
way, so wrap it in @supports over a regular grid.
// Masonry.js, or:
// measure every item and
// position it absolutely
new Masonry('.gallery', {
columnWidth: 200,
})
.gallery {
display: grid;
grid-template-columns:
repeat(auto-fill, minmax(7rem, 1fr));
}
@supports (display: grid-lanes) {
.gallery { display: grid-lanes; }
}