Product grids often need a "quick view" affordance: a button on a card that reveals a wider panel underneath it. The panel must sit directly below its trigger, span the full row width, and keep the existing cards in their original DOM and visual order — and the whole thing has to stay responsive. The solution is a handful of CSS Grid declarations, three of them no longer than a line. JavaScript remains in the picture, but only to handle interaction, not layout.

Below is the kind of grid this pattern was built inside, as it appears rendered in a component library:

A grid of product cards in a three by two layout. Each card has a placeholder gray image, product name, descriptions, price, and small text.

The starting grid

The base grid is the pattern used for the default grid system in general; the product cards are one instance of it. The following is simplified:

.grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fit, 20rem);
}

The key piece is grid-template-columns: repeat(auto-fit, 20rem);. It produces 20rem-wide columns that fill the available space automatically and wrap once the row runs out of room. minmax() can be used to make column widths flexible instead of fixed — auto-fit versus auto-fill is covered in detail in Sara Soueidan's linked explanation — but here the columns are deliberately fixed for simplicity.

Making a card span every column

Because the grid from the first step is an explicit grid, a full-width card can simply declare where it begins and ends:

.fullwidth {
  grid-column: 1 / -1;
}

1 / -1 means "start at column line 1, and run through to the very last column line." That gets the wide card into place with no extra markup — but leaves empty spaces above it.

Two rows of four rectangles. All of the rectangles are light gray and numbered, except one that has a wheat-colored background and another box beneath it containing text, and taking up the full container width.

Closing the holes

The gaps are filled using a trick borrowed from faux-masonry layouts:

.grid {
  grid-auto-flow: dense;
}

grid-auto-flow determines how the grid's auto-placement algorithm positions items, and the dense packing value makes that algorithm backfill holes it has already passed. Two conditions make this safe here:

  • Every column has the same width. Dense packing also works with flexible widths, e.g. minmax(20rem, 1f).
  • Every cell in a row has the same height, which is the default: the container implicitly carries align-items: stretch, so cells fill the row's available height.

The critical payoff is that the rendered result still follows the original source order despite the packing. That property is what keeps the pattern accessible. A full account of auto-placement mechanics is on MDN.

Layout in CSS, behavior in JavaScript

All three techniques together give the layout with no media queries and no JavaScript — yet a production implementation still needs script, just not for computing positions. That script handles click events, focus state, and showing or hiding the injected card.

In the prototype the full-width cards are hard-coded in the DOM in the right spots, and script merely toggles their display. In production the card would probably be fetched and inserted at the correct location: e-commerce product grids tend to have very heavy DOMs, so hiding lots of content in the page for later use adds avoidable weight. Treat the quick view as progressive enhancement: if JavaScript fails, the user should land on the relevant product details page.

Accessibility

The structural choices matter as much as the CSS:

  • The grid is a <ul><li> list, since it displays a list of products. Screen readers therefore announce the relationship between cards and the item count.
  • Each card is an <article> with proper headings.
  • Source order is preserved when the .fullwidth card is injected, so the natural tab order moves into the injected content and out again to the next card.

The initial version wrapped the grid in an aria-live region so DOM changes were announced, and moved focus programmatically to the injected card on open and back to the trigger on close. Both were revised after feedback. Announcements now come from treating the open and close buttons as toggle buttons with aria-expanded and aria-controls, the pattern used for disclosure widgets such as show/hide, tabs, and accordions — this behaved more like an inline modal than a disclosure. The injected card instead gets tabindex="0", letting keyboard users choose whether to move into it or simply toggle it closed. The <ul><li> structure is still considered right for a list of cards, because the semantics express an explicit relationship between them.

Optional production additions not shown in the prototype:

  • A label on the injected card when it takes focus — often just a heading as its first element.
  • ESC bound to close the card.
  • Scrolling the window so the card is fully within the viewport.

Where else this fits

This is a useful alternative to modals when extra content should be revealed without taking over the whole viewport. The same inline-expansion idea suits photo captions in an image grid, helper text, and even some cases where <details>/<summary> would be the reflex choice — though those elements are only a good fit in certain contexts.