Grid and Sizing
How the option buttons are arranged, and how tall the card is in a dashboard or inside a layout.
grid
grid arranges the option buttons as a CSS grid: how many columns, the gaps between buttons and the height of each row. Most menus need only columns and gap.
columnstakes a number for equal columns, or any CSSgrid-template-columnsvalue for columns of different widths (100px 1fr 2fr).- Each row is
56pxhigh unless you setgrid-auto-rows, and the buttons fill their cells. To place smaller buttons in their cells, give them a size inbutton_template(width,height) and setjustify-itemsoralign-items. rowssets a number of rows (eachgrid-auto-rowshigh) or a CSSgrid-template-rowstrack list. With the default row flow, options beyond those rows add more.
type: custom:lcards-select-menu
entity: input_select.demo_mode
preset: lozenge
grid:
columns: 2
gap: 6px
grid-auto-rows: 44pxMore about grid
- Column flow: with
grid-auto-flow: columnthe options fill each column top to bottom, so setrows: without it every option goes in one row. - Gap aliases:
row_gapandcolumn_gapare accepted as other spellings ofrow-gapandcolumn-gap; the dashed key wins when both are set. - Other CSS grid keys: the card builds the grid from the keys in this table only; other CSS grid properties under
gridhave no effect.
| Key | Type | Default | Description |
|---|---|---|---|
grid.columns | number / string | 1 | Number of equal-width columns (1 to 24), or a CSS grid-template-columns value |
grid.grid-template-columns | string | - | A CSS grid-template-columns value; wins over columns |
grid.gap | string | 4px | Gap between rows and between columns |
grid.row-gap | string | gap | Gap between rows; row_gap is an alias |
grid.column-gap | string | gap | Gap between columns; column_gap is an alias |
grid.grid-auto-rows | string | 56px | Row height, such as 48px, minmax(40px, 56px) or auto |
grid.grid-auto-flow | string | row | row, column, dense, row dense or column dense |
grid.rows | number / string | - | A number of rows, each grid-auto-rows high, or a CSS grid-template-rows value |
grid.justify-items | string | stretch | Each button's place across its cell: stretch, start, end or center. Places buttons with a button_template.width; without one they fill the cell across |
grid.align-items | string | stretch | Each button's place down its cell: stretch, start, end or center. Places buttons with a button_template.height; without one they fill the cell down |
grid.height | string | natural | fit or 100%: see Height modes |
Sizing in a Dashboard
In a sections view the card asks Home Assistant for enough grid rows to show every option. It works the rows out from the number of options, the columns, grid.rows, the row height and the row gap.
- The row height it counts is
grid-auto-rowsin pixels (the larger value ofminmax(Apx, Bpx)), or56pxfor anything else. A pixel track ingrid.rowscounts as given. - A pixel
heighton the card sizes it instead, and your owngrid_options.rowsalways wins. - The card asks for 4 grid columns unless
grid_options.columnssays otherwise. In a masonry view it reports one unit per row of options (or its pixelheightin 50 px units).
# 8 options in 4 columns: 2 rows, so a 2-row cell
type: custom:lcards-select-menu
entity: input_select.deck
preset: capped
grid:
columns: 4
gap: 4px
options:
- value: bridge
label: BRIDGE
- value: engineering
label: ENGINEERING
- value: sickbay
label: SICKBAY
- value: tactical
label: TACTICAL
- value: science
label: SCIENCE
- value: cargo
label: CARGO
- value: shuttle
label: SHUTTLE BAY
- value: holodeck
label: HOLODECK| Key | Type | Default | Description |
|---|---|---|---|
height | number / string | - | A fixed card height; a pixel value also sets the rows the card asks for. See Sizing |
grid_options.rows | number | enough for every option | Rows in a sections view; wins over the card's own count |
grid_options.columns | number | 4 | Columns in a sections view; the card can't be resized below 2 |
Height modes
grid.height lets a menu inside a layout size its parent's row, or fill a row the parent sizes. Leave it out and the option grid is as tall as its rows, and the card flows like normal content.
fitgives the card a fixed pixel height worked out from the config (rows × row height + gaps, the same count as Sizing in a Dashboard), so a parent row sized to its content (autoorminmax(0, max-content)) can follow it exactly. Measuring the menu through Home Assistant's card wrapper is unreliable; a definite height always works. It needs a pixelgrid-auto-rows(Npxorminmax(Apx, Bpx), which counts the larger value).100%makes the option grid fill the height its container gives it. The card measures the container and shares it between the rows (not the options: 4 options in 2 columns are 2 rows). Withoutgrid-auto-rowsthe rows take whatever share that is (down to 20 px), so a strip of tabs fits a 30 px row; with a pixelgrid-auto-rowsthey stay within its bounds; with a flexible maximum such asminmax(40px, 1fr), CSS shares the height out.- For a fixed card height with scrolling, use the card's own
heightandoverflow_yinstead.
This sidebar is the pattern the shell strategy uses: the menu's row hugs the menu, and a filler panel takes the rest.
type: custom:lcards-layout-card
height: 300
layout:
grid-template-columns: 1fr
grid-template-rows: minmax(0, max-content)
grid-auto-rows: minmax(40px, 1fr)
grid-gap: 5px
cards:
- type: custom:lcards-select-menu
entity: input_select.demo_mode
preset: lozenge
grid:
columns: 1
gap: 5px
grid-auto-rows: minmax(40px, 56px)
height: fit
view_layout:
# scrolls inside the menu if the container is too short
overflow-y: auto
- type: custom:lcards-button
preset: panel-dark
# lets the filler shrink with its row
min_height: 1More about height modes
- The parent row:
minmax(0, max-content)tracks the menu's published height exactly, capped by the container; the filler row (minmax(40px, 1fr)) takes the rest. - Buttons in rows that shrink: set a small
min_heighton them. Without one, the button preset's minimum height (56 px from the theme) keeps them painting at full size even in a collapsed row. - 100% when even the minimum does not fit: the buttons stay at the minimum row height and the option grid scrolls inside the card instead of spilling into the layout. Until the container has been measured (the first frame), the grid clips.
- Other values:
grid.heighttakes onlyfitand100%; anything else is ignored.
| Key | Type | Default | Description |
|---|---|---|---|
grid.height | string | - | Unset: as tall as the rows. fit: a fixed pixel height from the config. 100%: fill the container |
grid.grid-auto-rows | string | 56px | Must be Npx or minmax(Apx, Bpx) for fit. With 100%: unset, the rows share the container (20 px at least); a pixel value bounds them |