Skip to content

Grid

Align elements in grid.

Example

Preact

jsx
<Grid cols={3} gap="sm">
  <ColorSwatch color="#fff" />
  <ColorSwatch color="#eee" />
  <ColorSwatch color="#ddd" />
  <ColorSwatch color="#ccc" />
  <ColorSwatch color="#aaa" />
  <ColorSwatch color="#999" />
  <ColorSwatch color="#888" />
  <ColorSwatch color="#777" />
  <ColorSwatch color="#666" />
  <ColorSwatch color="#555" />
  <ColorSwatch color="#444" />
  <ColorSwatch color="#333" />
  <ColorSwatch color="#222" />
  <ColorSwatch color="#111" />
  <ColorSwatch color="#000" />
</Grid>

Custom Element

html
<phi-grid cols="3" gap="sm">
  <phi-color-swatch color="#fff" />
  <phi-color-swatch color="#eee" />
  <phi-color-swatch color="#ddd" />
  <phi-color-swatch color="#ccc" />
  <phi-color-swatch color="#aaa" />
  <phi-color-swatch color="#999" />
  <phi-color-swatch color="#888" />
  <phi-color-swatch color="#777" />
  <phi-color-swatch color="#666" />
  <phi-color-swatch color="#555" />
  <phi-color-swatch color="#444" />
  <phi-color-swatch color="#333" />
  <phi-color-swatch color="#222" />
  <phi-color-swatch color="#111" />
  <phi-color-swatch color="#000" />
</phi-grid>

Pure-CSS

html
<div class="phi-grid md" style="grid-template-columns: (3, max-content)">
  <span class="phi-color-swatch" style="background: #fff" />
  <span class="phi-color-swatch" style="background: #eee" />
  <span class="phi-color-swatch" style="background: #ddd" />
  <span class="phi-color-swatch" style="background: #ccc" />
  <span class="phi-color-swatch" style="background: #aaa" />
  <span class="phi-color-swatch" style="background: #999" />
  <span class="phi-color-swatch" style="background: #888" />
  <span class="phi-color-swatch" style="background: #777" />
  <span class="phi-color-swatch" style="background: #666" />
  <span class="phi-color-swatch" style="background: #555" />
  <span class="phi-color-swatch" style="background: #444" />
  <span class="phi-color-swatch" style="background: #333" />
  <span class="phi-color-swatch" style="background: #222" />
  <span class="phi-color-swatch" style="background: #111" />
  <span class="phi-color-swatch" style="background: #000" />
</div>

Gap variants

md variant (default)

Suitable to align normal elements.

sm variant (default)

Suitable to align options, tags, etc.

Reference

Preact

Properties

PropertyTypeDefaultDescription
gap'md'|'sm''md'Switch gap variants
align'left'|'center'|'right''left'Switch alignment variants
colsnumber|'auto-fit''auto-fit'Number of grid columns
colWidthnumber|'min-content'|'max-content'-Force column width
colMinWidthnumber|'min-content'|'max-content''max-content'Force min column width
colMaxWidthnumber|'min-content'|'max-content''max-content'Force max column width

NOTE: If you omit cols property, you usually want to specify colWidth instead (otherwise the grid may look like just a stack).

Custom Element

Props / Attrs

SlotCategoryTypeDefault
gapProp/Attr'md'|'sm''md'
alignProp/Attr'left'|'center'|'right''left'
colsProp/Attrnumber|'auto-fit''auto-fit'
colWidthPropnumber|'min-content'|'max-content''min-content'
colMinWidthPropnumber|'min-content'|'max-content''min-content'
colMaxWidthPropnumber|'min-content'|'max-content''min-content'
col-widthAttrnumber|'min-content'|'max-content''min-content'
col-min-widthAttrnumber|'min-content'|'max-content''min-content'
col-max-widthAttrnumber|'min-content'|'max-content''min-content'

Pure-CSS

Classes

Class
phi-gridCore styles
left, center, right, space-betweenAlignment variants
md, smGap variants