<p>Mods 2, 3, 4  and 5</p>
<p>
  <button data-add>add list item</button>
  <button data-remove>remove list item</button>
</p>
<ul>
  <li></li>
</ul>
<p>
<a href="https://css-tricks.com/examples/nth-child-tester/">css-tricks nth-child tester</a>
</p>
body {
  font-family: sans-serif;
}

p { 
  margin: 20px;
}

ul {
  counter-reset: item;
  list-style: none;
  margin: 0 20px;
  padding: 0;
}

li {
  background-color: silver;
  border: 1px solid darkslategrey;
  box-sizing: border-box;
  display: inline-block;
  margin: -1px 0 0 -1px;
  padding: 1.2rem;
  width: 50%
}
li::before {
  counter-increment: item;   
  content: "Item " counter(item) ;
}
li::after {
  font-size: 80%;
  opacity: .5;
}

li:first-child:not(:nth-last-child(2n)):not(:nth-last-child(3n)):not(:nth-last-child(5n)) {
  text-align: center;
  width: 100%;
}

li:only-child::after {
  content: " (only child) ";
}
li:first-child:not(:only-child):not(:nth-last-child(2n)):not(:nth-last-child(3n)):not(:nth-last-child(5n))::after {  
  /* length not matched below */
  content: " (no mod selector match) ";
}

li:nth-last-child(2n):first-child,
li:nth-last-child(2n):first-child ~ li {
  /* list can be divided by 2 */
  &:after {
    content: " (mod 2)";
  }
}

li:nth-last-child(3n):first-child,
li:nth-last-child(3n):first-child ~ li {
  /* list can be divided by 3 */
  background-color: lightsalmon;
  width: 33%;
  &:after {
    content: " (mod 3)";
  }
}

li:nth-last-child(4n):first-child,
li:nth-last-child(4n):first-child ~ li {
  /* list can be divided by 4 */
  background-color: gold;
  width: 25%;
  &:after {
    content: " (mod 4)";
  } 
}


li:nth-last-child(5n):first-child,
li:nth-last-child(5n):first-child ~ li {
  /* list can be divided by 5 */
  background-color: moccasin;
  width: 20%;
  &:after {
    content: " (mod 5)";
  }
}

$("[data-add]").on('click', function() {
  var l = $("li").length;
  $("ul").append("<li></li>");
})
$("[data-remove]").on('click', function() {
  $("li:last").remove();
})

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

  1. https://code.jquery.com/jquery-2.2.4.min.js