<div class="container">
  <div></div>
  <div></div>
  <div></div>
  <div></div>
  <div></div>
</div>
.container {
  display:flex;
  flex-wrap:wrap; /* this */
  gap:10px;
}
.container > div {
  height:100px;
  flex:max(400px, 100%/3 - 20px); /* and this */
  background:red;
}

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.