0

I have a table and I want to shade each alternate row, apart from the row with the class "openingTimes".

This opening times row should not be shaded, but the pattern after this row should be continued, like this, (with bold representing shading!):

[ Info 1 ] [ Info 2 ] [ Opening Times Row ] [ Info 3 ] [ Info 4 ] [ Info 5 ] [ Info 6 ]

The CSS I have is:

table tr:not(.openingTimes):nth-child(even)
{
    background-color: #eeeeee;
}

But what this results in is:

[ Info 1 ] [ Info 2 ] [ Opening Times Row ] [ Info 3 ] [ Info 4 ] [ Info 5 ] [ Info 6 ]

I want the Info 3 to be shaded and the pattern to continue from there.

What am I doing wrong? Thanks!

Edit: OK, here's a fiddle: http://jsfiddle.net/QWjnm/

BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
Fiona - myaccessible.website
  • 14,481
  • 16
  • 82
  • 117

1 Answers1

5

The nth-child syntax isn't complex enough to allow for what you want.

In your example however, you can write

tr:first-child, tr:nth-child(2n+4)

for a selector.

This means use the first child, and also every even child starting at the fourth.

See updated fiddle.

It's not an ideal solution; you don't have any control over the openingTimes class any more, but I can't think of any solution where you do. Sorry!

Mr Lister
  • 45,515
  • 15
  • 108
  • 150
  • "every other child starting at the fourth." is wrong, it's every other **even** child starting at the fourth. – Apolo Apr 28 '15 at 15:30
  • @Apolo Hey, "every other" does not mean the same as "every". Look it up. And I'm not even sure the sentence is grammatically correct after your edit. – Mr Lister Apr 28 '15 at 16:28
  • I just wanted to precise, but english is not my favorite language, re-edit if you think it's wrong – Apolo Apr 28 '15 at 16:29
  • but "every other child starting at the fourth" make me think it's 4,5, 6 and so on... – Apolo Apr 28 '15 at 16:30
  • @Apolo But it really means 4, 6, 8 and so on. I can edit so that it is both correct and clear though... – Mr Lister Apr 28 '15 at 16:32