User avatar

Jeroen Reumkens PRO

Css Grid Auto-fit With Limits

Unlock Playgrounds

Build, test and share frontend ideas right in your browser.

Choose a plan

Cancel anytime. Playgrounds are also included in PRO. Upgrade later and we credit 100% of your first 3 months and 50% of the rest toward it.

Already a member? Log in

Playground settings

Playground

Anyone with the link can view it. Private playgrounds are only visible to you.

Editor

Applied right away

Files in the same folder share one tab.

Packages

Importable from your code, loaded from esm.sh

No packages yet.

.wrapper {
container: inline-size;
}

.grid {
--preferred-size: 300px;
--max-columns: 4;
--column-size: calc(
max(
calc((100cqw / var(--max-columns)) - var(--gap-size) * (var(--max-columns) - 1)),
var(--preferred-size))
);
--gap-size: 8px;
display: grid;
gap: var(--gap-size);
grid-template-columns: repeat(auto-fit, minmax(var(--column-size), 1fr));
}

.grid > div {
background: #ccc;
}
  • No matching files
↵ open⌘↵ open to the sideesc close