JSFiddle - React, Tailwind, and code Playground

by davidxmartins

HTML

<div class="container">
  <div class="item">Element 1</div>
  <div class="item">Element 2</div>
  <div class="item">Element 3 (Elements stretch according to their content)
  </div>
</div>

CSS

.container {
  display: flex;
  /* Set the space between items */
  row-gap: 20px;
  column-gap: 20px;
  flex-wrap: wrap;
}

/* Ensure each item flex-grow to use all available space */
.item {
  flex-grow: 1;
  background: lightgrey;
  text-align: center;
  padding: 20px;
}

@media (max-width: 700px) {
  .item {
    /* Allow each item to occupy all available space per line */
    flex-grow: 0;
    flex-basis: 100%;
  }
}