<h2>Target first child</h2>
<ul class="not-first">
  <li>First child</li>
  <li>Second Child</li>
  <li>Last Child</li>
</ul>

<h2>Target last child</h2>
<ul class="not-last">
  <li>First child</li>
  <li>Second Child</li>
  <li>Last Child</li>
</ul>

<h2>Target nth child</h2>
<ul class="second-child">
  <li>First child</li>
  <li>Second Child</li>
  <li>Last Child</li>
</ul>
ul.not-first > li:not(:first-child){
  margin-top: 20px;
}

ul.not-last > li:not(:last-child){
  margin-bottom: 20px;
}

ul.second-child > li:not(:nth-child(2)){
  margin: 20px 0;
}

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.