Skip to content
AITroveRead. Build. Understand.
Make this comfortable

CSS grid tracks: reserve a sidebar without letting content widen the page

Last updated: 5 Oct 20265 min read
tutorial
BeginnerBy AITrove Editorial

Grid lays out items against rows and columns. Fractional tracks share remaining space, but intrinsic minimums can still force a track wider than its container.

How the rule works

A receipt record has a main narrative and a metadata sidebar. The narrative can contain a long code, so its track must be allowed to shrink. The sidebar has a controlled width, and the layout becomes one column once both tracks no longer fit. Keep the main narrative first in the DOM even if a mockup places the sidebar visually elsewhere. A grid cell with a long preformatted block may also need min-inline-size: 0 and a local scroll container; one rule cannot solve every overflowing child.

css
.receipt-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(14rem, 18rem);
  gap: 1.25rem;
}
.receipt-layout > * { min-inline-size: 0; }
@media (max-width: 50rem) {
  .receipt-layout { grid-template-columns: minmax(0, 1fr); }
}

Cost and verification

The browser computes track sizes on layout; the practical cost is usually a too-rigid design, not the grid algorithm. Check long identifiers, translated headings, and zoom before settling on the breakpoint. The 50rem threshold is a content-driven starting point for this example, not a device category. If the sidebar is optional, ensure it follows the narrative in reading order when the grid collapses.

Common Mistakes

  • Do not assume 1fr means a track can always shrink to zero.
  • Do not move the sidebar in CSS while leaving an incoherent reading order.
  • Do not hide overflow on the whole page to conceal one wide child.

Connected lessons

Extend this decision

Property decisions

css
layout
web
Storage details