Grid to adjust columns as desktop viewport shrinks

Hello there.

So I thought what I wanted to do, would be quite simple, but apparently it’s not, or I’m just terrible at searching for the relevant information…

Basically what’s happening is: on the desktop breakpoint, I have a little ‘gallery’ using CSS Grid with 3 columns. What I would like to happen is, as the viewport shrinks, I would like for the number of columns to adjust, so that the images don’t go out of view of the viewport.

I can easily go to the next smaller breakpoint, the tablet one, and just change that to one column. But that doesn’t help me in the desktop viewport, when incrementally shrinking the viewport until the images go out of frame. I would love for them to simply go down to 2 columns, and then 1, as needed.

I’ve tried deleting two rows, just making it ONE row, and then using ‘auto-fit’. But then the gallery images just start to overlap each other as the screen shrinks.

What I thought the answer would be, would be to set a ‘custom breakpoint’, at for example 1600 px, where you could define exactly when it should switch to 2 columns, and lastly one column.

And I’ve now spent maybe 3 hours on this, playing around with everything I can think of, watching videos on grid in Webflow, and it’s always about just clicking on the tablet breakpoint, adjusting it, and boom you’re done. But that doesn’t solve shrinking the viewport on the desktop breakpoint down to something around 1600 px wide.

Any help would be greatly appreciated!


Here is my site Read-Only: Webflow - Strange Island Creative

hi @onawave it will newer work as expected as you have fixed width of your link to 500px and also on your grid cell you have set minimal: 500px/1fr.

That is why your gallery overflow on width that is smaller that 3 cells + 2 gaps

(3 * 500) + (2 * 51) = 1653

Reset these and set link or img width to 100% and grid cell to 1fr only to make it work. You can also optionally set your gallery block to flex or grid.

The best you can do is take some free course on CSS Grid to understand how Grid works to prevent further issues you may face.

Right! Yes that makes sense, thank you very much. I really shouldn’t have had a hard coded fixed width for the image divs. I’m still quite new to this stuff (learning web development stuff for a few months), so my first instinct is to just input in pixels the size I want things, going off of my Figma design.

I definitely should dive deep into CSS grid as well, that’s for sure. That will be my next thing to get a handle on. I learned Flex reasonably, but hadn’t gotten to Grid yet. I was working my way through the Odin Project, and just started on the full stack javascript part.

But anyways, I appreciate it! I’m gonna play around some more, and see where I get. But that’s a great tip, cause I was hung up on that.

Cheers!

it is not a tip @onawave , it is the solution :hugs: