
A row of cards does not always need separate two-column and three-column breakpoints. Let CSS Grid fit as many readable cards as the container allows. This small pattern works well for service summaries, lesson cards, and other collections where the content should decide when to wrap.
Change the CSS below. The preview updates as you type. Your edits stay in this browser tab.
Use the width control. Change the minimum card width or gap to see when columns wrap.
HTML for this example
<div class="responsive-grid"><article><span>01</span><h2>Design</h2><p>Give the idea a clear visual direction.</p></article><article><span>02</span><h2>Build</h2><p>Turn the approved design into a useful website.</p></article><article><span>03</span><h2>Refine</h2><p>Test the details on real screen sizes.</p></article></div>
Give every track a useful minimum
repeat(auto-fit, minmax(min(100%, var(--card-min)), 1fr)) creates as many tracks as fit. Each grows to share the remaining space. The inner min(100%, ...) prevents the minimum track width from being wider than a very narrow container. Try 10rem and 15rem for --card-min, then move the preview width control.
Understand auto-fit before swapping it
auto-fit collapses empty tracks, allowing the remaining cards to expand. auto-fill retains those track spaces. Neither is universally better: decide whether a short final collection should stretch or preserve more empty room. With three cards, resize the preview and watch how both the number of tracks and their widths change.
Give difficult content room to wrap
A long URL, an unbreakable identifier, or a fixed-width child can still overflow a well-built grid. The demo uses min-width: 0 and wrapping for those cases. Test real content and text zoom. If your design requires an exact editorial arrangement, explicit breakpoints may still be the clearer choice.
Reference: MDN on repeat().
Have a client website that needs this kind of attention? See our WordPress development for agencies and case studies.


Leave a Reply