Phase 3 — Layout
#12 Layout patterns
holy grail, cards, sidebar, sticky footer
Holy grail layout
The classic web layout with header, sidebar, main content, and footer:
Holy grail with Grid
.page {
display: grid;
grid-template-areas:
"header header"
"sidebar main"
"footer footer";
grid-template-columns: 250px 1fr;
grid-template-rows: auto 1fr auto;
min-height: 100vh;
}
.header { grid-area: header; }
.sidebar { grid-area: sidebar; }
.main { grid-area: main; }
.footer { grid-area: footer; }
/* Responsive: stack on mobile */
@media (max-width: 768px) {
.page {
grid-template-areas:
"header"
"main"
"sidebar"
"footer";
grid-template-columns: 1fr;
}
}Card grid
Responsive card grid
.cards {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
gap: 24px;
}
.card {
border: 1px solid #e0dbd4;
border-radius: 12px;
overflow: hidden;
}
.card-body {
padding: 20px;
}
.card-img {
width: 100%;
aspect-ratio: 16 / 9;
object-fit: cover;
}Sticky footer
Footer always at bottom
.page {
display: grid;
grid-template-rows: auto 1fr auto;
min-height: 100vh;
}
/* header = auto height */
/* main = fills remaining space */
/* footer = auto height, always at bottom */Centered content
Max-width centered container
.container {
max-width: 1200px;
margin: 0 auto; /* Center horizontally */
padding: 0 24px; /* Gutters on mobile */
}
/* Perfect centering */
.hero {
display: grid;
place-items: center;
min-height: 100vh;
}Split layout
Two-column split
.split {
display: grid;
grid-template-columns: 1fr 1fr;
min-height: 100vh;
}
.split-left {
background: #1a1a2e;
color: white;
display: grid;
place-items: center;
}
.split-right {
padding: 48px;
}Your turn
Try the layout pattern commands below:
terminal — browser