Issue:
The problem lies in the fact that :last-child
does not work as intended. It only selects the last child of the container regardless of its class, and last-of-type
is limited to selecting the last element with a specific type within the container.
Solution:
To address this issue, it is recommended to create a dedicated class for the desired element:
.micropost {} .micropost.pinned {
color: red;
}
.micropost:last-child {
color: green;
}
.lastPinned {
background-color: green;
}
<ul>
<li class="micropost pinned">1</li>
<li class="micropost pinned lastPinned">2</li>
<li class="micropost">3</li>
<li class="micropost">4</li>
<li class="micropost">5</li>
<li class="micropost">6</li>
<li class="micropost">7</li>
</ul>