fomicz
fomicz

Reputation: 1792

Why :first-child select all children?

I want to select only the very first links from "dropdown menu" (the ones with "ONE" text), but :first-child selects them all.

Link:

http://jsfiddle.net/773Xd/1/

Sorry for the mess in the HTML part, but I'm customizing Wordpress theme and it produces so many classes and ids.

The most important thing is at the end of CSS file.

Upvotes: 9

Views: 9058

Answers (1)

alex
alex

Reputation: 490263

Change your CSS selector to this...

#page-navigation ul li .sub-menu li:first-child a

(i.e. put pseudo class :first-child on the li, not the a).

See it on jsfiddle.net

The old selector didn't work because a is always the first child of the li elements.

But in the new selector, the li is the first child of the ul elements.

Upvotes: 17

Related Questions