Why some css styling methods works others don't?

When we created a navigation bar and using just list and tried to change the color of the last element in element using .

li: last-of-type
{
color: red;
}
this did not work.

next thing which we try was by providing id to the last element and it also did not work.

but by providing
li: last-of-type a
{
color: red;
}

color changed. why did this happen and other methods did not work ?

How shall we n=know which will work and which will not.

This doubt for video Nagarro Bootcamp Websession-5 at around 18 minute.

Hi @gaurav7cpw

Please use slack channel to ask doubts for Live batches.