title: Alternating row colours with nth-child and nth-of-type
body: <p><strong>Contrary to the duplicate notice</strong>, this question is not a duplicate. The purported duplicate does not address the case of nesting, something I've clearly explained in my question.</p>
  
  <p>I have a table where rows can have one of two classes: <code>parent</code> or <code>child</code>. Some parents have many children, while others have no children. The HTML structure of the table, being flat, can not represent the hierarchical relationship between the rows; both parents and children are <code>tr</code>s. Example:</p>
  
  <pre><code>Parent A
  Child  1
  Child  2
  Parent B
  Parent C
  Child  1
  </code></pre>
  
  <p>I would like to stripe the rows so that odd and even parent rows have a color, and their respective children will have a lighter shade of the parent color.</p>
  
  <p>Please see the included snippet for an example of what I'm trying to achieve.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="true">
  <div class="snippet-code snippet-currently-hidden">
  <pre class="snippet-code-css lang-css prettyprint-override"><code>table {
    border-collapse: collapse;
    width: 100%;
  }
  
  td {
    border: 1px solid #eee;
    padding: 10px;
  }
  
  .parentOdd {
    background-color: #eb94fa;
  }
  
  .parentEven {
    background-color: #c294fa;
  }
  
  .oddChild {
    background-color: #f2c4fa;
  }
  
  .evenChild {
    background-color: #d8bbfd;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;table&gt;
    &lt;tbody&gt;
      &lt;tr class="parentOdd"&gt;
        &lt;td&gt;Parent A&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr class="oddChild"&gt;
        &lt;td&gt;A1&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr class="oddChild"&gt;
        &lt;td&gt;A2&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr class="parentEven"&gt;
        &lt;td&gt;Parent B&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr class="parentOdd"&gt;
        &lt;td&gt;Parent C&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr class="oddChild"&gt;
        &lt;td&gt;C1&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr class="oddChild"&gt;
        &lt;td&gt;C2&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr class="parentEven"&gt;
        &lt;td&gt;Parent D&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr class="evenChild"&gt;
        &lt;td&gt;D1&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr class="evenChild"&gt;
        &lt;td&gt;D2&lt;/td&gt;
      &lt;/tr&gt;
    &lt;/tbody&gt;
  &lt;/table&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>I tried using CSS pseudo-selectors, but no luck.</p>
  
  <pre><code>.parent:nth-child(odd) {
    background-color: green;
  }
  .parent:nth-child(even) {
    background-color: blue;
  }
  </code></pre>
  
  <p>The <code>nth-child</code> selector ignores the class. I tried using <code>nth-of-type</code> but that also ignored the class. And besides, both pseudo-selectors can't handle the case of the children.</p>
  
  <p>Is what I'm trying to do possible in CSS? Or do I have to resort to JavaScript?</p>