Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can someone explain why the "nth-child"-selector has a higher priority than "hover"?

Yesterday I ran into this: One of my :hover-states stopped working. I found out that If I change this:

div.item {}
div.item:hover {}
div.item:nth-child(even) {}

to this:

div.item {}
div.item:nth-child(even) {}
div.item:hover {}

it works again.

I've created a demo on jsfiddle to show both cases.

Can somebody explain, why the :hover-state is overwritten by the selector?

like image 783
insertusernamehere Avatar asked Oct 24 '12 18:10

insertusernamehere


People also ask

Which selector is highest priority?

Values defined as Important will have the highest priority. Inline CSS has a higher priority than embedded and external CSS. So the final order is: Value defined as Important > Inline >id nesting > id > class nesting > class > tag nesting > tag.

Which CSS selector is faster?

popupbutton is the fastest.

What's the difference between the nth of type () and Nth child () selector?

The nth-of-type is very similar to the nth-child pseudo-class. The main difference is that it specifically considers the type of the element getting selected before checking any other logic. Let's use our example from above but apply nth-of-type instead.

What is priority order for CSS selector?

Calculating a selector's specificity The priority level of the selector is decided in Point of combination of selectors. "article p span" are "a=0, b=0, c=0, d=3 (0003)". "#red" is "a=0, b=1, c=0, d=0 (0100)". In this instance, paragraph becomes a red character.


1 Answers

The selectors have the same specificity, so the one that comes last takes priority.

like image 91
Guffa Avatar answered Nov 15 '22 12:11

Guffa