Kevin Powell - CommunityKP-C
Kevin Powell - Community15mo ago
34 replies
KesSaft

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?

<div className="images">
        {room.images.map((image, index) => (
          <img key={index} className={`image-${index}`} src={image} />
        ))}
      </div>

main .images {
  display: grid;
  grid-auto-flow: column;
  grid-template-columns: repeat(auto-fill, min(200px, 15dvw));
  grid-template-rows: repeat(2, min(200px, 15dvw));
  gap: 10px;
  overflow-x: auto;
  width: 100%;
  flex-shrink: 0;
}

main .images img {
  height: 100%;
  width: 100%;
  aspect-ratio: 1/1;
  object-fit: cover;
  border-radius: min(20px, 2dvw);
}

main .images .image-0 {
  grid-column: span 2;
  grid-row: span 2;
}
image.png
Was this page helpful?