Reputation: 5
Why is this? Both blockquotes are blue. The TR's do alternate in color, but the blockquotes will not. How come?
<tr>
<blockquote>Hello</blockquote>
</tr>
<tr>
<blockquote>Hello</blockquote>
</tr>
tr:nth-child(even){ background-color: #272727; }
tr:nth-child(odd) { background-color: #222222; }
blockquote:nth-child(even){ background-color: red; }
blockquote:nth-child(odd) { background-color: blue; }
Upvotes: 0
Views: 66
Reputation: 207861
Use nth-of-type
instead:
tr:nth-of-type(even) {
background-color: #272727;
}
tr:nth-of-type(odd) {
background-color: #222222;
}
tr:nth-of-type(even) blockquote {
background-color: red;
}
tr:nth-of-type(odd) blockquote {
background-color: blue;
}
jsFiddle example (colors changed for visibility)
Upvotes: 2
Reputation: 10682
Both block quotes are the 1st element of their respective parents, which is odd... Therefore: blockquote:nth-child(odd) is true.
Upvotes: 0