So im trying to use css grid to make a gallery for pictures liek pinterest. So diffrent height pictures to be next to each other and each picutre to take over the empty space. But all the examples i see are with adding diffrent classes on each picture depending on their height they want and i want to add pictures dynamically from a data base.
I tried like this: My gallery component:
<div className=‘gallery’>
<img className=‘image’> </img>
<img className=‘image’> </img>
<img className=‘image’> </img>
<img className=‘image’> </img>
</div>
And my css file:
.gallery{
max-width: 80vh;
display: grid;
grid-template-columns:repeat(3,1fr);
}
.image{
max-width: 200px;
height: 100%;
object-fit: cover;
}
But like this the small picutres are in the same row and the bigger picutres in another when i need it to be randomised.
Is there any way to do it without adding different classes om each picture?