olee
olee

Reputation: 1

Child element wont work

i have a problem that if i type 1 nothing happen, but if i type 2 it make changes to the first div :S.

http://d.pr/m07l

do you know what im doing wrong

Upvotes: 0

Views: 87

Answers (2)

andyb
andyb

Reputation: 43823

:nth-child() is 1-indexed and :nth-child(1) will select the first child. If it is not selecting what you want, there must be another child that is actually first. Maybe it's the header… in your example image.

Since it is the header (thanks for the link to your site), you should use :nth-of-type() instead to consider just the <div class="newsPost"> when counting.

Upvotes: 2

Quasdunk
Quasdunk

Reputation: 15220

It's because the first and the last child have their own selectors:

:first-child

and

:last-child

So you have to use .newsPost:firstChild instead of .newsPost:nth-child(1).

Upvotes: 0

Related Questions