title: Trying to use CSS class Together with Nth- child selector
body: <p>Hi I have looked at a variety of resources including Stackoverflow on how to use an Nth child selector and Class together and so far I am still failing. </p>
  
  <p>Essentially my menu has Main categories (class =cat) and sub categories (class=subcat) </p>
  
  <p>I want Each of the Main categories to be coloured differently. sub categories all stay the same. it is likely there may be multiple subcats in between each main cat. So, example: </p>
  
  <p><strong>Beef</strong><br>
       steak<br>
       roast<br>
  <strong>Chicken</strong><br>
       Breast<br>
       drumsticks<br>
       wings<br>
  <strong>Fish</strong><br>
       Salmon<br></p>
  
  <p>I can make it work so long as I don't put the class in - the instant the class goes in the nth-child selector fails. </p>
  
  <p>css: </p>
  
  <pre><code>    #nav ul li.cat a {
  display:block;
  background-color: #265054;
  font-size: 1em;
  padding-left: 25px;
  height: 18px;
  padding-top: 2px;
  margin: 1px 0px;
  color: #FFFF00;
  
  }
  
  #nav ul li.cat a:nth-child(2)  {
  background-color: #728c8c;
  }
  </code></pre>
  
  <p>Code:</p>
  
  <pre><code>&lt;?php 
      if (count($navlist)){ 
          echo "&lt;ul&gt;"; 
          foreach ($navlist as $key =&gt; $list){ 
              foreach ($list as $topkey =&gt; $toplist){ 
                  echo "&lt;li class='cat'&gt;"; 
                  echo anchor("welcome/cat/$topkey",$toplist['name']); 
                  echo "&lt;/li&gt;\n"; 
  
                  if (count($toplist['children'])){ 
                      foreach ($toplist['children'] as $subkey =&gt; $subname){ 
                          echo "\n&lt;li id='subcat'&gt;"; 
                          echo anchor("welcome/cat/$subkey",$subname); 
                          echo "&lt;/li&gt;"; 
                      } 
                  } 
              } 
          } 
  
          echo "&lt;/ul&gt;\n"; 
      } 
  ?&gt;
  </code></pre>
  
  <p>Many Thanks for all your help ! </p>