<div class="wrapper">
  <h3>"At-most" Quantity Query (Breakpoint: at most 5 elements)</h3>
  <p><strong>Default color:</strong> blue, <strong>Color set by quantity query:</strong> orange</p>
  <ul>
    <li>1.</li>
    <li>2.</li>
    <li>3.</li>
  </ul>
  <ul>
    <li>1.</li>
    <li>2.</li>
    <li>3.</li>
    <li>4.</li>
  </ul>
  <ul>
    <li>1.</li>
    <li>2.</li>
    <li>3.</li>
    <li>4.</li>
    <li>5.</li>
  </ul>
  <ul>
    <li>1.</li>
    <li>2.</li>
    <li>3.</li>
    <li>4.</li>
    <li>5.</li>
    <li>6.</li>
  </ul>
  <ul>
    <li>1.</li>
    <li>2.</li>
    <li>3.</li>
    <li>4.</li>
    <li>5.</li>
    <li>6.</li>
    <li>7.</li>
  </ul>
</div>
<!-- End of .wrapper -->
ul li:nth-last-child(-n+5):first-child,
ul li:nth-last-child(-n+5):first-child ~ li {
  background-color: orange;
}

.wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
}

p {
  margin-top: 0;
}

ul {
  margin: 0.3125rem 0.3125rem 0.625rem;
}

li {
  display: inline-block;
  width: 4rem;
  height: 4rem;
  list-style-type: none;
  margin: 0.3125rem;
  background-color: royalblue;
  color: white;
  font-size: 2rem;
  text-align: center;
  line-height: 2;
}
Rerun