<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div class="container">    
    <h3>:first-child, :last-child and :nth-child()</h3>
    <ul>
      <li>1st child</li>
      <li>2nd child</li>
      <li>3rd child</li>
      <li>4th child</li>
      <li>5th child</li>
      <li>6th child</li>
      <li>7th child</li>
      <li>8th child</li>
      <li>9th child</li>
      <li>10th child</li>
    </ul>
    
    <h3>:first-of-type, :last-of-type and :nth-of-type()</h3>
    <div class="flex">
      <span>1st of type</span>
      <span>2nd child</span>
      <span>3rd child</span>
      <span>4th child</span>
      <span>5th child</span>
      <span>6th child</span>
      <span>7th child</span>
      <span>8th child</span>
      <span>9th child</span>
      <span>last of type</span>
    </div>
  </div>
</body>
</html>
li:first-child{
  color: red
}
li:last-child{
  color: green
}
li:nth-child(3n){
  color: #F4BE2C
}
.flex{
  display: flex;
  flex-wrap: wrap
}
span{
  border: 1px solid #3DBE29;
  padding: 5px;
  margin: 3px
}

span:first-of-type{
  background-color: #DE4839;
}

span:last-of-type{
  background-color: #38CC77;
}
span:nth-of-type(3n){
  background-color: #F4BE2C;
}

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.