<!-- Learn about this code on MDN: https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Grid_Layout/Auto-placement_in_CSS_Grid_Layout -->

<ul class="wrapper">
   <li class="item"><img src="http://placehold.it/200x300" alt="placeholder"></li>
   <li class="item"><img src="http://placehold.it/200x300" alt="placeholder"></li>
   <li class="item"><img src="http://placehold.it/200x300" alt="placeholder"></li>
   <li class="item item--landscape"><img src="http://placehold.it/350x200/000/fff" alt="placeholder"></li>
   <li class="item"><img src="http://placehold.it/200x300" alt="placeholder"></li>
   <li class="item"><img src="http://placehold.it/200x300" alt="placeholder"></li>
   <li class="item"><img src="http://placehold.it/200x300" alt="placeholder"></li>  
</ul>
.wrapper {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  grid-gap: 10px;
  grid-auto-flow: dense; /* The magic is here */
  list-style: none;
  margin: 1em auto;
  padding: 0;
}

.item {
  border: 1px solid #ccc;
}

.item--landscape {
  grid-column-end: span 2;
}

.item img {
   display: block;
   object-fit: cover;
   width: 100%;
   height: 100%;
}

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.