Why wrapping the whole card with CardWrapper collapses each card into a skinny vertical line 🚧
What changes when you add the wrapper?
html
<a class="block"> ← now *this* is the direct grid child
<div class="relative w-full max-w-[280px] h-[320px] …">
…card content…
</div>
</a>
The grid item used to be the <div> with max-w-[280px].
After the change the grid item is the <a>.
How CSS-Grid sizes “auto / block” elements💡
• An element whose width is auto inside a grid contributes its min-content width to the track sizing algorithm.
• A bare <a class="block"> with no explicit width has a min-content width that is basically zero (it only contains a single child that wants to be 100 % of its parent, but the parent is “indefinite”).
• Grid therefore allocates a near-zero inline size to each <a>.
• The inner .max-w-[280px] div then overflows its parent, so visually you’re left with a 1-pixel-ish sliver → “a vertical line”.
Why you didn’t notice this with the plain card
When the card div itself is the grid child, it does have max-w-[280px], so its min-content width is 280 px and the track is sized correctly.
How to fix it ✅
Make sure the wrapper element itself has a definite width/height so the grid can size it properly.
tsx
const CardWrapper = ({
children,
link
}: {
children: React.ReactNode;
link?: string;
}) =>
link ? (
<a
href={link}
target="_blank"
rel="noopener noreferrer"
// 👇 stretch to fill its grid cell
className="block w-full h-full"
>
{children}
</a>
) : (
<div className="block w-full h-full">{children}</div>
);
or, if you want to keep the max-w constraint on the outermost element:
tsx
className="block w-full max-w-[280px] h-[320px]"
Either way, giving the wrapper an explicit w-full (and usually h-full) (or the same max-w / h as the card) lets the grid algorithm see the real size, so each card goes back to its intended 280 × 320 px box instead of collapsing into a line.
Alternative pattern (no wrapper width issues)
Instead of wrapping the whole card, place a transparent link on top of it: