Build cards for the space they get
Use named container queries to make one editorial card work in a wide main column and a narrow sidebar, with real examples and a practical review checklist.

A reusable card often looks finished in the page where it was designed. Move it into a sidebar, a search panel or a dashboard column, and the assumptions show up: a title loses its breathing room, the thumbnail crowds the copy, and the action drops out of view. The component knows the browser is wide, but its own space is narrow.
Give an AI coding agent two placements to satisfy at once. In this original study, the same editorial card appears in an 850px main column and a 300px sidebar within one 1440px viewport. It carries the same headline, summary and link in both. Only its arrangement needs to change.
Let the allocated space choose the arrangement
Actual Chromium capture of our original fictional card study. Labels report measured container widths. The wide placement is horizontal; the sidebar remains stacked.A page breakpoint can decide whether the sidebar belongs next to the main content. The card needs a different decision: whether its own image and text can comfortably sit beside each other. Keeping those decisions separate makes a component easier to reuse without teaching it every page layout in the product.
Choose the scope that owns the decision
Viewport-level layout
The page arranges its major regions.
- Place or stack a navigation rail.
- Move a sidebar below the main content.
- Change the page’s overall column structure.
Container-level composition
A component responds to its allocated space.
- Place the card image beside its copy.
- Keep a compact card stacked and readable.
- Reuse the same component in multiple page regions.
This split is a design judgment, not a rule that every component needs a query. A simple text link may only need natural wrapping. Add a layout switch when it produces a clearer reading order or a more useful relationship between the elements.
Put the query on an ancestor, and style the card inside it
MDN’s container query guide describes an inline-size containment context for size queries. Name that context when the component should respond to a particular ancestor. In the example, the slot establishes editorial and the descendant card receives the conditional layout. The CSS Containment specification defines container selection through eligible ancestors; a card does not query its own size to restyle itself.
Three layers with separate responsibilities
Page region
Allocates space to the main area or sidebar. Its layout can still use viewport-based rules.
Named slot
Establishes the editorial inline-size query context around the reusable card.
Descendant card
Starts with a stacked base. A matching query enables its horizontal arrangement when the slot is wide enough.
.card-slot {
container: editorial / inline-size;
}
.editorial-card {
display: block;
min-width: 0;
}
.editorial-card h2 {
overflow-wrap: anywhere;
}
@container editorial (min-width: 32rem) {
.editorial-card {
display: grid;
grid-template-columns: 42% minmax(0, 1fr);
}
}
The wrapper and card are separate elements. In our study, 32rem is an illustrative threshold: it gives the image and copy enough room to sit alongside one another with the chosen font, padding and content. Choose a threshold by watching the composition become comfortable, then test nearby widths. A familiar device label is not evidence that a component has enough space.
Review the worst reasonable content
Short sample titles make almost any card look sturdy. Give the agent one longer headline, a narrow placement and a real link target. Ask it to keep the meaning visible rather than silently truncate every difficult case. In this study, the long title is allowed to wrap and the reading link remains in the document flow.
Actual desktop capture after enabling the study’s Long title control. The same content is repeated intentionally to compare placements. Separate 390px captures are retained with the study’s browser checks.Inspect the image as well as the text. A thumbnail that works in a wide row may need a different crop in a stacked card. Here the artwork is decorative and drawn with CSS, so the title and link carry the meaning. A real content image would need its own suitable alternative text and a crop that preserves the subject.
Questions to answer before calling the card reusable| Test | Inspect | Evidence from this study |
|---|
| Two placements, one viewport | Does each card react to its own width? | 850px main area becomes horizontal; 300px sidebar stays stacked. |
| Narrow viewport | Can the text and action remain visible? | At 390px both cards stack without page overflow. |
| Longer title | Does content wrap without covering the action? | The extended headline remains visible in both placements. |
| Keyboard navigation | Is the reading link a real, reachable link? | Keyboard activation reaches the study note. |
| Base layout | Is the component usable without the enhancement? | Disabling the query rules leaves the card stacked. |
Make the default composition worth keeping
The stacked card is the base design. The wider arrangement is an enhancement. That gives the component a useful result before a size query matches. In the study, the Base layout control removes the enhancement so we can inspect that result directly. It is a deliberate test control, not a claim that we tested every browser without container query support.
CSS feature queries can condition declarations on support, as described in MDN’s @supports reference. A positive syntax check still does not tell you whether your title fits, whether a link has a useful name or whether focus is visible. Review those behaviors in the actual rendered component.
Build one editorial card and render it in two differently sized slots.
Use a named ancestor container for component-level layout changes.
Keep a readable stacked base before the query matches.
Preserve DOM order and use a real reading link.
Test a longer title, narrow width, keyboard focus and the base layout.
Capture the two placements in the same viewport with measured widths.
We checked the authored demonstration in Chromium at 1440px and 390px, including the longer title, keyboard link activation and base-layout control. No page overflow or JavaScript errors occurred. This is a practical component review, not a performance benchmark or a complete accessibility audit. The useful outcome is a clearer contract: the page gives the card space, and the card makes a readable composition within it.
Back to the LOOKFILE blog