<h2>Full Container</h2>
<ul>
  <li></li>
  <li></li>
  <li></li>
  <li></li>
  <li></li>
  <li></li>
  <li></li>
  <li></li>
</ul>

<h2>Narrow Container</h2>
<ul class="narrow">
  <li></li>
  <li></li>
  <li></li>
  <li></li>
  <li></li>
  <li></li>
  <li></li>
  <li></li>
</ul>
ul {
    display: grid;
    grid-gap: 1rem;
    grid-template-columns: 1fr;

    background: lightgray;
    list-style: none;
    padding: 0;
  }

  @media (min-width: 12em) {
    ul {
      grid-template-columns: repeat(auto-fill, minmax(10rem, 1fr));
    }
  }

ul > * {
  background: black;
  height: 10rem;
}

.narrow {
  margin-left: auto;
  margin-right: auto;
  max-width: 9rem;
}
Run Pen

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.