<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: repeat(auto-fill, minmax(min(10rem, 100%), 1fr));

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

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.