Software and updates
Ready CSS snippets: a centred card and a responsive grid, original code
Two short snippets we wrote ourselves: a centred card with flexbox and a responsive grid with repeat and minmax, with what each line does and what we did not test.
Last reviewed:
CSS n/a Web
A centred card
We put the card inside a flex container and centre it both ways with justify-content and align-items; the container gets a min-height so there is height to centre in. .card-wrap { display: flex; justify-content: center; align-items: center; min-height: 60vh; } .card { max-width: 28rem; padding: 1.5rem; border: 1px solid #ddd; border-radius: 0.75rem; }
A responsive grid
The key line is repeat with auto-fit and minmax: columns form at no less than 14rem and share leftover space at 1fr, so the column count drops on narrow screens. .grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr)); }
Before you copy
- Colours and sizes are examples; change them to suit your design.
- Test on a phone and a desktop width.
- No code here runs on our server; it is text you copy.
Licence and source limits
The code is original and you may use and edit it freely. We read MDN's repeat and minmax pages on 1 December 2026 only to confirm the syntax. We did not test the code in browsers and state no browser support.
Related pages
Sources
- MDN: repeat() CSS function · read on
- MDN: minmax() CSS function · read on
Wording is ours, from the official source. Images and video belong to their owners and are credited with a link to the official page.