To know about nth-child, first-child and last-child classes in css, we can see the example, it will be easier to understand.
Code:
<ul>
<li><span></span></li>
<li><span></span></li>
<li><span></span></li>
<li><span></span></li>
<li><span></span></li>
<li><span></span></li>
<li><span></span></li>
<li><span></span></li>
<li><span></span></li>
<li><span></span></li>
<li><span></span></li>
<li><span></span></li>
</ul>
Css code:
Code:
li:nth-child(8) span {
background-color: red;
}
then Li number 8 will have red background
Code:
li:nth-last-child span {
background-color: green;
}
then last Li (number 12) will have green background
Code:
li:nth-first-child span {
background-color: black;
}
then Li number 1 will have black background
Sometimes, I used to use this technique to identify exact classes that I want to make it in style