0

I currently have a container with items having varying heights. I'm displaying them in columns of 5 and 3 items max per line. I tried the following implementation but there are huge gaps in the row that I can't seem to remove. How would I fix this?

body {
  background-color: #1E1E1E;
  display: flex;
  justify-content: center;
}

.masonry {
  width: 1200px;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  grid-template-rows: repeat(3, auto);
  grid-row-gap: 10px;
}

.cell {
  background-color: #fff;
  width: 240px;
  margin: 10px;
}
<div class="masonry">
  <div style="height: 180px" class="cell"></div>
  <div style="height: 240px" class="cell"></div>
  <div style="height: 520px" class="cell"></div>
  <div style="height: 120px" class="cell"></div>
  <div style="height: 240px" class="cell"></div>
  <div style="height: 332px" class="cell"></div>
  <div style="height: 143px" class="cell"></div>
  <div style="height: 306px" class="cell"></div>
  <div style="height: 514px" class="cell"></div>
  <div style="height: 232px" class="cell"></div>
  <div style="height: 361px" class="cell"></div>
  <div style="height: 234px" class="cell"></div>
  <div style="height: 318px" class="cell"></div>
</div>
Lee Taylor
  • 7,761
  • 16
  • 33
  • 49
devAR
  • 349
  • 7
  • 21

1 Answers1

0

I believe a structure like this with elements cover everywhere is what you need: example

it can be achieved by grid-area or by using grid-column-start, grid-column-end, grid-row-start, and grid-row-end for each element based on how you want them to be positioned.
you can read more about it here

Rawand
  • 377
  • 3
  • 11