العربية
Back

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

Wording is ours, from the official source. Images and video belong to their owners and are credited with a link to the official page.

#css#html#snippets#grid#flexbox#exec#dev

Frequently asked questions

What is the difference between auto-fit and auto-fill?

Both are used inside repeat; the source we read shows both forms but we did not read the full explanation of the difference, so check MDN before relying on specific behaviour.

What does minmax(14rem, 1fr) do?

It defines a size range no smaller than the minimum and no larger than the maximum, used with CSS grids, per MDN.

Can I use the code on my site?

Yes, it is original code we wrote and you may use and edit it.

Was it tested in every browser?

No, we did not test it, so try it in your own browsers before publishing.