Skip to content

Grid

Based on CSS Grid, this layout component offers powerful 2D layout capabilities compared to Row/Col Flex layouts.

Basic Usage

Set cols to define columns and gap for spacing.

1
2
3
Basic Usage

Column Span

Use span to set how many columns a GridItem spans.

span=2
span=3
span=1
span=6 (full row)
Column Span

Offset

Use offset to set column offset.

A
B (offset=2)
Offset

Different Gaps

gap accepts an array [rowGap, colGap] for separate row and column gaps.

1
2
3
4
5
6
7
8
Different Gaps

Custom Column Template

When cols is a string, it's used directly as CSS grid-template-columns value.

200px
1fr
200px
Custom Column Template

Suffix Element

Set suffix to pin a GridItem to the end of the row.

Content
Suffix
Suffix Element

Use in Nuxt

Grid fully supports Nuxt 3/4 SSR rendering. The example below demonstrates a product list page using Grid layout with useFetch for async data loading.

Product List

Product 1
$ 99.9
Product 2
$ 199.8
Product 3
$ 299.7
Product 4
$ 399.6
Use in Nuxt

SSR Notes:

  • ✅ All Props and styles fully supported
  • ✅ CSS Grid layout renders correctly
  • ✅ Slot content renders completely
  • ✅ String cols template mode outputs correctly
  • span, offset, suffix positioning props work perfectly

SSR Safety

Grid component has passed complete SSR tests, ensuring consistent rendering between server and client with no Hydration errors.

API

Grid Props

PropDescriptionTypeDefault
colsColumns count or CSS templatenumber | string12
gapGapnumber | string | [number | string, number | string]0
colGapColumn gap (overrides gap)number | string0
rowGapRow gap (overrides gap)number | string0
collapsedCollapsedbooleanfalse
collapsedRowsCollapsed visible rowsnumber1
justifyItemsHorizontal alignment'start' | 'end' | 'center' | 'stretch'
alignItemsVertical alignment'start' | 'end' | 'center' | 'stretch'
themeOverridesTheme overridesComponentThemeVars

GridItem Props

PropDescriptionTypeDefault
spanColumn spannumber1
offsetColumn offsetnumber0
suffixSuffix element (pinned to row end)booleanfalse
themeOverridesTheme overridesComponentThemeVars

Slots

Both Grid and GridItem support the default slot.

Theme Variables

Grid component supports the following CSS variables for theme customization:

Grid Variables

Variable NameDescriptionDefault
--yh-grid-gapGrid gap0
--yh-grid-col-gapGrid column gapvar(--yh-grid-gap, 0)
--yh-grid-row-gapGrid row gapvar(--yh-grid-gap, 0)

GridItem Variables

Variable NameDescriptionDefault
--yh-grid-item-paddingItem padding0

Released under the MIT License.