How to fix :last-child not working as expected with CSS?

Spread the love

To fix :last-child not working as expected with CSS, we should make sure the element we’re selecting is the last element.

For instance, we write

<div>
  <a></a>
  <a>This will be selected</a>
</div>

to add 2 a elements into the div.

Then we write

div a:last-child {
}

to select the last a element in the div with div a:last-child.

Leave a Reply

Your email address will not be published. Required fields are marked *