I am trying to make a div that contains 4 images display each image evenly so it shows 3 images with a gap of 20px. This div should be scrollable so the final image can be scrolled to, however I can't seem to make it overflow through css grid.
Closest I've got it is this, however there is no overflow-x containing the final image
To achieve this I wrote the following code for my grid. I'm aware grid-template-rows set to 100% is causing the issue, but I'm not sure of an alternate method:
.container {
width: 100%;
height: 100%;
}
.images {
height: 200px;
width: 100%;
display: grid;
grid-template-columns: repeat(3, 1fr);
grid-template-rows: 100%;
gap: 20px;
overflow-x: scroll;
}
.images img {
object-fit: cover;
object-position: center;
width: 100%;
height: 100%;
}
<div class="container">
<div class="images">
<img
src={image}
/>
<img
src={image}
/>
<img
src={image}
/>
<img
src={image}
/>
</div>
</div>
Alternatively, I have tried using flexbox with each image having 33.3% width, however getting this to work with a 20px gap seems too 'hacky'.
Thanks