Horizontal Grid Image Gallery
I want to create such a image gallery basically. This is what I already have but my problem is, that the last columns only shrink when there are more images added but the images should all stay the same size but it should be horizonally scrollable.
Any idea?
20 Replies
you have auto-fit and want it to overflow?
thats ... yeah, that wont work
if you want auto-fit, it will never overflow
and if you want it to overflow, you cant have autofit
so is there another way to do it then without autofit?
what you can try is to add a parent that has overflow-x: auto
and remove the
width
on the div with the imagesna, still shrinking the images
what works it settings the width to max-content, but then it takes far to many columns into account 😄
you can try to play around with grid-auto-flow
i would try
column dense
just setting it to dense and the images div to width max-content works to some extend
it doesn't scroll too far
but it doesn't align it that well
setting it to
column dense
doesn't change anythingyou have to set the grid-auto-columns to 1fr, so it takes the same size as the others
or ... try with flex
no, still nothing.
display: flex; flex: 1 1 300px;
or somethingbut how would I do that so I keep the layout with the first one beeing bigger
you can set the first one to have 2x the flex size, but im not sure if it would work well 🤔
the crazy and inneficient idea is to use grid and then flex on the other images
this is what I get using flex
you mean grid with one row and then flex for the images in columns
what I could do is to not use auto-fill in the grid but calculate it using the available images.
that would be the efficient way
or just set it to a really high number
I think that is actually the best option in my case as there is a max of 10 images the user can display in this way... 😄
But thanks for your effort!!
you're welcome
do you mean like so? https://codepen.io/MarkBoots/pen/wvVPaVg
😮
the code is clean af
and no
auto-fit