UI Layout Patterns: Cards, Media Objects, Sticky Footers
Most interface work is recombination. A landing page is a hero, a feature grid, a pricing row, a testimonial band; an app screen is a toolbar, a list of media objects, a detail panel. Each piece has a battle-tested CSS shape â often five or six declarations deep â and the difference between a junior and a senior implementation is not creativity, it is knowing the shapes cold and knowing where each one breaks on a narrow screen. This lesson catalogues the patterns that recur across this site's layouts: what problem each encodes, the minimal CSS that implements it, and the responsive and accessibility decisions that turn a screenshot into something shippable. Everything here uses only the layout systems covered earlier â Flexbox, Grid, and the unit and overflow tools â so the value is entirely in the composition.
Card grids that survive long content
A card grid is repeat(auto-fit, minmax(min(100%, 18rem), 1fr)) â the same media-query-free gallery from the grid patterns lesson â wrapped around a card whose internal structure holds up when titles run long. The structural rules that keep cards sane: the image keeps its aspect ratio with aspect-ratio and object-fit: cover, the body grows, and the actions row pins to the bottom with margin-top: auto (in a flex column) so buttons align across every card in a row regardless of title length:
.card-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(min(100%, 18rem), 1fr));
gap: 1.5rem;
padding: clamp(1.5rem, 4vw, 3rem);
}
.card {
display: flex;
flex-direction: column;
background: #ffffff;
border: 1px solid #e2e8f0;
border-radius: 16px;
overflow: clip;
transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.card:hover {
transform: translateY(-4px);
box-shadow: 0 16px 32px #0f172a1a;
}
.card img {
width: 100%;
aspect-ratio: 16 / 9;
object-fit: cover;
}
.card .body {
padding: 1.25rem;
flex: 1;
}
.card .title {
font-size: 1.15rem;
font-weight: 700;
margin: 0 0 0.5rem;
}
.card .summary {
margin: 0;
color: #475569;
display: -webkit-box;
-webkit-line-clamp: 3;
-webkit-box-orient: vertical;
overflow: hidden;
}
.card .actions {
display: flex;
justify-content: space-between;
align-items: center;
gap: 0.75rem;
padding: 0.85rem 1.25rem;
border-block-start: 1px solid #f1f5f9;
}
The hover lift uses transform and box-shadow â composite-friendly, no layout movement beyond the translate. Two hover cautions: :hover styles must be mirrored under @media (hover: hover) on touch devices to avoid sticky hover states, and if the whole card is clickable, make one real link inside it stretch with ::after { content: ""; position: absolute; inset: 0 } rather than slapping onclick on the container â keyboard users get a focusable target for free.
The media object, still undefeated
The media object â avatar beside text, icon beside notification, thumbnail beside result â predates Flexbox and fits it perfectly. The original implementation floated the image and cleared it; the flex version is clearer and handles variable-height siblings better. The only two properties people forget are flex-shrink: 0 on the fixed-size media (so it never crushes to a sliver) and min-width: 0 on the text column (so long words wrap instead of overflowing):
.media {
display: flex;
gap: 1rem;
align-items: flex-start;
}
.media + .media {
margin-block-start: 1rem;
}
.media .avatar {
flex: 0 0 auto;
width: 48px;
height: 48px;
border-radius: 50%;
object-fit: cover;
}
.media .content {
flex: 1;
min-width: 0;
}
.media .content .headline {
font-weight: 600;
margin: 0 0 0.25rem;
}
.media .content .meta {
font-size: 0.85rem;
color: #64748b;
}
.media.is-reversed {
flex-direction: row-reverse;
}
Stretched children need align-self overrides in some designs, but align-items: flex-start is the safe default: it keeps each row's avatars aligned to their own content rather than centering everything against the tallest item. For responsive stacks (avatar above text on narrow screens), flex-wrap: wrap plus a media width of calc(100% - âĻ) gets you there without touching the markup.
Sticky footers, three ways
The stranded-footer problem â a page whose footer floats halfway down the screen when content is short â has three solutions, all short:
| Approach | Declaration | Trade-off |
|---|---|---|
| Flex column | .page { display: flex; flex-direction: column; min-height: 100vh } with .content { flex: 1 } | Works everywhere; flex on the page root |
| Grid rows | .page { display: grid; grid-template-rows: auto 1fr auto; min-height: 100vh } | Same result, preferred if the page already uses grid |
| Modern grid | .page { display: grid; grid-template-rows: auto 1fr auto; min-height: 100dvh } | Adds dynamic viewport height for mobile URL bar |
.page {
display: grid;
grid-template-rows: auto minmax(0, 1fr) auto;
min-height: 100vh;
min-height: 100dvh;
}
.site-main {
min-width: 0;
}
.site-footer {
padding: 2rem clamp(1rem, 4vw, 3rem);
background: #0f172a;
color: #94a3b8;
}
Use minmax(0, 1fr) for the content row for the usual overflow reason, and remember the dvh fallback line so mobile browsers with collapsing URL bars do not leave a white gap. The margin-top: auto variant works too (.content { flex: 1 } in a flex column), but once display: grid exists on the page for other reasons, the row approach is more consistent.
Split screens and featured sections
The split-screen hero â brand panel beside content panel â is one grid with a media query, and the featured section (image beside copy) is the same pattern minus the full height:
.split {
display: grid;
grid-template-columns: 1fr 1fr;
min-height: 100dvh;
}
.split .brand-panel {
display: flex;
flex-direction: column;
justify-content: center;
gap: 1.25rem;
padding: clamp(2rem, 6vw, 5rem);
background: #1d4ed8;
color: #ffffff;
}
.split .content-panel {
display: flex;
flex-direction: column;
justify-content: center;
padding: clamp(2rem, 6vw, 5rem);
}
.featured {
display: grid;
grid-template-columns: minmax(0, 1.1fr) minmax(0, 0.9fr);
gap: clamp(2rem, 5vw, 4rem);
align-items: center;
padding: clamp(2.5rem, 7vw, 6rem);
}
.featured img {
width: 100%;
border-radius: 16px;
}
@media (max-width: 800px) {
.split,
.featured {
grid-template-columns: minmax(0, 1fr);
}
}
align-items: center on .featured is the detail that makes unequal-height columns feel intentional â image and copy align on their centers. On the mobile collapse, consider reversing the source order with order only when reading order still makes sense; otherwise let the document order win for screen readers.
Pricing rows and testimonials
Pricing tables are auto-fit minmax grids around centered cards, with the featured tier emphasized by a scale transform and a border â remember that a scaled card overflows its cell visually, so reserve padding. Testimonials are the media object again with a larger avatar and italic quote. Both benefit from the same rhythm rule: one spacing scale (the clamp gap from the units lesson) applied everywhere, so sections feel related:
.pricing {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(min(100%, 17rem), 1fr));
gap: clamp(1rem, 3vw, 2rem);
max-width: 64rem;
margin-inline: auto;
padding: clamp(2rem, 6vw, 5rem);
}
.plan {
background: #ffffff;
border: 1px solid #e2e8f0;
border-radius: 18px;
padding: clamp(1.5rem, 4vw, 2.25rem);
text-align: center;
display: flex;
flex-direction: column;
gap: 1rem;
}
.plan.is-featured {
border: 2px solid #2563eb;
transform: translateY(-8px);
box-shadow: 0 20px 40px #2563eb1f;
}
.plan .price {
font-size: clamp(2rem, 1.5rem + 2vw, 2.75rem);
font-weight: 800;
}
.plan .features {
list-style: none;
padding: 0;
margin: 0;
flex: 1;
text-align: start;
color: #475569;
}
.plan .cta { margin-block-start: auto; }
The featured plan's negative translateY is pure transform, so it does not push neighbors; the extra margin budget comes from the grid gap. Keep the CTA margin-block-start: auto so buttons bottom-align across tiers of different feature counts â the same bottom-alignment trick as cards.
Choosing between these and a framework
Every pattern above is under twenty lines of CSS and has no runtime. A component framework still wins when the design system is shared across teams, when you need the JS behaviors (dialogs, menus, carousels with buttons), or when tokens are mandated â but the layout itself should remain these primitives so the framework can be swapped without rewriting structure. The durable skill is not memorizing a library's class names; it is seeing a screenshot and knowing it is an auto-fit grid, a flex media object, and a 1fr auto row footer stacked together.
Skeletons and empty states
Every list, feed, or dashboard eventually renders with nothing to show, and both moments are layout patterns in their own right. The empty state is a centered stack â icon, message, action â that needs a height floor so it does not collapse into one line at the top of the screen:
.empty-state {
display: grid;
place-items: center;
gap: 0.75rem;
min-block-size: 16rem;
padding: clamp(2rem, 6vw, 4rem);
text-align: center;
color: #64748b;
}
.empty-state .title {
font-size: 1.1rem;
font-weight: 600;
color: #0f172a;
}
.skeleton-row {
display: flex;
gap: 1rem;
align-items: center;
padding: 1rem;
}
.skeleton-avatar {
inline-size: 48px;
block-size: 48px;
border-radius: 50%;
flex: 0 0 auto;
}
.skeleton-lines {
flex: 1;
display: grid;
gap: 0.5rem;
}
.skeleton-lines span {
block-size: 0.85rem;
border-radius: 4px;
background: linear-gradient(90deg, #e2e8f0 25%, #f8fafc 50%, #e2e8f0 75%);
background-size: 200% 100%;
animation: shimmer 1.4s ease infinite;
}
.skeleton-lines span:last-child { inline-size: 60%; }
@keyframes shimmer {
to { background-position: -200% 0; }
}
The skeleton is the media-object pattern again with placeholders standing in for the avatar and text, plus a shimmer built from an animated background position â a paint-only animation that keeps loading states smooth. Keep skeleton geometry matched to the real content's dimensions: rows, avatars, and line counts should mirror what will appear, or the page visibly jumps when data arrives. Under prefers-reduced-motion: reduce, drop the shimmer to a static tint. And when the loading resolves to nothing, swap the skeleton for the empty state rather than leaving a blank region â the two patterns are halves of one loading story, and shipping only the happy path is what makes sparse interfaces feel unfinished.
Common Mistakes
Card buttons sit at different heights across a row
Fix: Make the card a flex column with a flex: 1 body and margin-block-start: auto (or auto via a spacer) on the actions row
Avatar shrinks when the text column gets long
Fix: Set flex-shrink: 0 on fixed media and min-width: 0 on the text column so each does its own job
Footer floats mid-page on short screens
Fix: Give the page scaffold min-height: 100vh (with a 100dvh line after it) and a 1fr middle row or a growing content area
Sticky hover effects appear permanently on touch devices
Fix: Wrap :hover rules in @media (hover: hover) and mirror the affordance on :focus-visible instead
Best Practices
- Compose pages from a fixed catalog of patterns instead of inventing per-page layouts
- Keep one spacing scale (clamp-based) across sections for visual rhythm
- Prefer transform and shadow for card hover feedback; never change layout size on hover
- Bottom-align actions in cards and pricing tiers with auto margins
- Verify each pattern at 320px before shipping â auto-fit grids and min-width: 0 are what make that width work
Interview Questions
Q1: How do you align buttons at the bottom of cards with different content lengths?
Make the card a flex column, give the body flex: 1 so it absorbs leftover space, and set margin-block-start: auto on the actions row (or rely on the body's growth pushing it down). The buttons then share a baseline across the grid row.
Q2: Why does the media object need both flex-shrink: 0 and min-width: 0?
The fixed-size avatar must never be crushed by long content (flex-shrink: 0), while the text column must be allowed to shrink below its content's min-content width so long words wrap instead of overflowing (min-width: 0). Each property fixes the failure mode of the other column.
Q3: What makes a layout pattern framework-independent?
It is expressed in the platform's own primitives â grid tracks, flex items, clamp() values â with no utility classes or JS runtime required. The structure survives a framework swap because the CSS depends only on standard layout semantics, which is why knowing the patterns matters more than memorizing any library.
Key Takeaways
- Card grids combine auto-fit minmax tracks with flex-column cards, aspect-ratio media, and auto-pushed action rows
- The media object is flex with flex-shrink: 0 on media and min-width: 0 on content
- Sticky footers are a grid of auto 1fr auto with min-height: 100dvh (fallback 100vh first)
- Split screens and featured sections are two-column grids with a single mobile collapse rule
- Pricing and testimonial layouts reuse auto-fit grids, transform-based emphasis, and the shared spacing scale
- Patterns beat frameworks when the primitives are what you actually maintain