`<pacem-masonry>` stacks its children ("bricks") into lanes, each one where the lanes are *shortest*, in document
order: the wall of an art catalog, a pinboard, a gallery of mixed shapes. It is native **CSS Grid Lanes** where the
browser has it, and a script reproducing the very same placement everywhere else.
```html
<pacem-masonry column-width="12rem">...bricks...</pacem-masonry>
<pacem-repeater datasource="{{ #works.model }}">
<pacem-masonry><template>...one brick...</template></pacem-masonry>
</pacem-repeater>
```
## Usage
**Drop bricks in.** Every child of the masonry is a brick: any element, of any height. A brick goes to the lane that
is shortest at that moment, so the wall stays balanced while the reading order (left to right, top to bottom) follows
the document.
**Size the lanes, not the bricks.** The lanes always fill the available width. `column-width` is their *minimum*
width, so their count follows the room (more lanes on a wide screen, fewer on a phone); `column-count` is their
*maximum* count. Together they work as in CSS multi-column layout: as many lanes as fit, never more than the count,
and the width wins when the two clash. With neither, the lanes are at least `16rem` wide. The bricks take the width of
their lane: give an image `width: 100%` (or `aspect-ratio`) and let its height follow.
```html
<!-- as many 12rem lanes as fit -->
<pacem-masonry column-width="12rem">...</pacem-masonry>
<!-- exactly 4 lanes -->
<pacem-masonry column-count="4">...</pacem-masonry>
<!-- 12rem lanes, 4 at most -->
<pacem-masonry column-width="12rem" column-count="4">...</pacem-masonry>
```
**Repeat them.** With a repeater, the `<template>` goes *inside* the masonry, so the items are its children.
```html
<pacem-repeater datasource="{{ #works.model }}">
<pacem-masonry>
<template><figure>...</figure></template>
</pacem-masonry>
</pacem-repeater>
```
**Span lanes.** A brick takes more lanes with the grid classes: `cols-2`, `cols-lg-3`, and the other breakpoints.
It goes where the tallest of the lanes it covers is lowest. The lane itself is never the brick's choice: the
`cols-start-*` and `rows-*` classes do not apply.
> Bricks are *measured*: an image that loads, a caption that wraps, a brick added or removed, a lane count that
> changes, the masonry follows it. Known proportions (`aspect-ratio`, or `width`/`height` on the image) save the
> wall a jump when the pictures arrive.
**Native or not.** `native` tells which engine is at work: `true` with `display: grid-lanes` (Safari today), `false`
with the scripted fallback, which places the bricks exactly where the native layout would.
## Customization
The masonry is a bare layout: no colors, no borders. Lanes and gaps are four custom properties, which the
`column-width`, `column-count`, `gap` and `tolerance` properties set on the element, and a stylesheet may set as well.
```css
.my-wall {
--pacem-masonry-column-width: 14rem; /* default 16rem */
--pacem-masonry-column-count: 5; /* default: no maximum */
--pacem-masonry-gap: 12px; /* default: the grid spacing */
--pacem-masonry-tolerance: 0px; /* default 0 */
}
```
A count alone, from a stylesheet, still meets the default minimum width: set the width to `0px` for exactly that many
lanes (the `column-count` property does it on its own).
`tolerance` is how much *shorter* a lane must be to win. At `0` the shortest lane always wins (the classic catalog
wall); a little tolerance (`1em`, as CSS Grid Lanes defaults to) keeps nearly level lanes in reading order instead.
Bricks are styled as any other element: surfaces, paddings, radii from the theme utilities.
## Examples
### A highlight that spans Lanes of at least 8rem, four at most; the featured work takes two lanes (`cols-2`), then three on large screens (`cols-lg-3`).
```html
<!-- <pacem-masonry>: lanes of at least 8rem, 4 at most;
the third brick spans -->
<pacem-repeater datasource="{{ #works.model }}">
<pacem-masonry column-width="8rem" column-count="4" gap="12px">
<template>
<!-- the grid classes span lanes: 2, then 3 on large screens -->
<pacem-panel css-class="{{ { 'cols-2': ^index === 2,
'cols-lg-3': ^index === 2 } }}">
...
</pacem-panel>
</template>
</pacem-masonry>
</pacem-repeater>
```
### Load more The catalog way: six works at a time. New bricks go on top of the wall as it is, nothing already placed moves.
```html
<pacem-data id="shown" model="6"></pacem-data>
<!-- <pacem-masonry>: added bricks are placed, nothing else moves -->
<pacem-repeater datasource="{{ #works.model.slice(0, #shown.model) }}">
<pacem-masonry column-width="8rem">
<template>...</template>
</pacem-masonry>
</pacem-repeater>
<pacem-button on-click="#shown.model = #shown.model + 6">Load more</pacem-button>
```
To provide the best experiences, we use technologies like cookies to store and/or access device information. Consenting to these technologies will allow us to process data such as browsing behavior or unique IDs on this site. Not consenting or withdrawing consent, may adversely affect certain features and functions.