Use This Simple Line Of CSS Grid To Make Your Layout Responsive
Published Mar 28, 2024
If youβre using CSS Grid for your layout, you can avoid writing a bunch of media queries with this simple line of CSS.
css
.grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
} Letβs break it down:
repeatusesauto-fillas the repeat count to repeat the grid item as many times as neededminmaxspecifies a minimum size of200px, and maximum size of1frfor the grid item
You could also use auto-fit instead of auto-fill, but what is the difference?
If you want to stretch the grid items to take the entire available space use auto-fit, otherwise use auto-fill.