← CodePrimer
CSS
Intermediate
Layout
Responsive card grid
How do I make cards auto-fit columns?
auto-fit minmax grid.
.grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
gap: 1rem;
}
Notes
Columns grow/shrink automatically with viewport width.
Keywords: grid · auto-fit · minmax · cards · responsive
Related
CSS
Three ways to apply CSS
What are inline, internal, and external CSS?
CSS
CSS box model
Why is my element wider than expected?
CSS
Margin vs padding
What is the difference between margin and padding?
CSS
display block inline flex
How does display change layout?
CSS
CSS position values
How do I pin an element or overlap layers?
CSS
CSS custom properties
How do I reuse colors with variables?