Mar 28, 2026
How can I use CSS Grid's auto-fill and minmax() functions to create a fully fluid image gallery that changes the number of columns automatically without using media queries?
The Problem: Traditional grids use @media (max-width: 768px) to force columns to change. This is tedious to maintain.
2 Comments
๐ฌ Discussion (2)
Rishi Pandey
Student Builder โข Barkatullah University
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px; } .gallery img { width: 100%; height: 100%; object-fit: cover; display: block; } 1. repeat(auto-fill, โฆ) Automatically creates as many columns as can fit No need to define column count manually 2. minmax(200px, 1fr) Each column: Minimum width = 200px Maximum = flexible (1fr = equal share of space) ๐ So: If screen is wide โ more columns fit If screen shrinks โ columns reduce automatically
Related Discussions
๐๐จ๐๐ข๐ง๐ ๐ข๐ฌ ๐ฌ๐จ ๐ฆ๐ฎ๐๐ก ๐ฆ๐จ๐ซ๐ ๐ญ๐ก๐๐ง ๐ฐ๐ซ๐ข๐ญ๐ข๐ง๐ ๐ฅ๐ข๐ง๐๐ฌ ๐จ๐...
by Rishi Pandey๐ HackerRank vs LeetCode: Which One Should B.Tech Students Choose? ๐ป If you'r...
by Rishi PandeyHey Seniors Can We juniors join some good seniors here or any WhatsApp communiti...
by anchan kapriImagine you are building an AI pipeline for a high-stakes domain (like fraud det...
by Mahak ThakurI recently participated in PromptWars โ Build with AI 2026, organized by Google ...
by Rishi Pandey