JSFiddle - React, Tailwind, and code Playground

by Jordan Sayner

HTML

<div class="container">
  <label class="label">Label</label>
  <span class="span1">This is span 1</span>
  <span class="span2">This is a</span>
</div>

CSS

.container {
  display: grid;
  grid-template-columns: auto auto auto; /* Each item takes its own space */
  gap: 10px; /* Space between items */
  align-items: center; /* Vertically align items */
}

.label {
  background-color: lightblue;
  transition: all 0.3s ease;
}

.span1, 
.span2 {
  white-space: nowrap; /* Prevent spans from breaking internally */
}

@media (max-width: 500px) { 
  /* Adjust to the point where spans would wrap */
  .container {
    grid-template-columns: 1fr 1fr; /* Forces spans to wrap */
  }

  .label {
    grid-column: 1 / -1; /* Make the label span the entire row */
    width: 100%; /* Full width of the container */
  }

  .span1, 
  .span2 {
    justify-self: start; /* Keep the spans at their natural width */
  }
}