Back to Concepts
CSS UniverseTrack 3: Flexbox & GridCSS Subgrid
Advanced Grid AlignmentCore Concept 12
CSS Subgrid
Never suffer from misaligned card buttons again. grid-template-rows: subgrid allows nested child components to participate directly in their parent grid tracks.
1. The Problem Subgrid Solves
The Misaligned Card Nightmare
Imagine 3 pricing cards side-by-side. Card 1 has a 1-line title, but Card 2 has a 3-line title. In regular CSS, each card handles its own layout, causing the buttons at the bottom to sit at staggered heights!
Starter
Essential tools for students getting started.
$0/mo
Professional Growth & Enterprise Multi-Branch Bundle
Advanced clustering, dedicated GPU engines, and unlimited cloud storage.
$49/mo
Team Pro
Collaborate with team members.
$19/mo
2. The Syntax
How to Declare a Subgrid
/* 1. Parent defines explicit rows */
.pricing-grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
grid-template-rows: auto 1fr auto;
}
/* 2. Child card inherits row tracks! */
.card {
grid-row: span 3; /* Spans all 3 parent rows */
display: grid;
grid-template-rows: subgrid; /* Inherits! */
}
Next in Track 3
Continue to Multi-Column13. Multi-Column Layout
column-count, column-width, column-gap, and spanning headlines.