brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: grid-template-rows: subgrid lines up card titles and footers in css grid

Css
~/tips/tip-css-grid-subgrid-card-rows

.card { display: grid; grid-row: span 3; grid-template-rows: subgrid; }

Lets nested grid items share the tracks of the parent grid so content lines up across cards.

Cards of different content lengths look untidy when each one has its own row sizes.

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(16rem, 1fr)); gap: 1rem; }
.card  { display: grid; grid-row: span 3; grid-template-rows: subgrid; }

With subgrid a grid item reuses the row (or column) tracks of its parent grid instead of making its own. Each card spans three rows of the parent, so when a card has three children, every title, body and footer sits on the same line across a whole row of cards. The item has to span the tracks it wants to share, and the parent’s gap is inherited unless you override it. Subgrid has worked in every major browser since September 2023.

Further reading: MDN: Subgrid

More Css tips CSS Overview in Chrome DevTools audits the colors and fonts of a page .notice:empty { .toast { article { counter-reset: h2; } .toolbar { All Css tips (66) All topics

Link