tags:

views:

51

answers:

5

Hi,

I have the following:

<ul id='foo'>
  <li class='fooitem'>
    <ul class='grok'>
      <li class='grokitem'></li>
    </ul>
  </li>
</ul>

I want to style the fooitem elements differently than the grokitem elements:

#foo li {
  background-color: red;
}

.grok li {
  background-color: green;
}

but the #foo li definition is overriding the .grok li definition, so all are appearing red. How do I define a style for the grok items?

Thanks

+2  A: 

You can do it by creating a more specific rule like so:

#foo li {
    background-color: red;
}

#foo .grok li {
    background-color: green;
}
Pat
A: 

Since your lis appear to have classes assigned to them, you can target them specifically, like so:

ul.grok li.grokitem
{
    /* your styles here */
}
Tim S. Van Haren
+6  A: 

You need a slightly different style rule (currently the first, with an ID, has a greater level of specifity).
You can resolve it like this:

#foo li {
  background-color: red;
}

#foo .grok li {
  background-color: green;
}

You can give it a try here

Nick Craver
A: 
#foo li {
  background-color: red;
}

#foo .grok li {
  background-color: green;
}
Tudorizer
A: 

You don't need any classes in your example

#foo li { background-color: red; } // All <li>s in foo

#foo li li { background-color: green; } // All <li>s in <li>s in foo
mikemerce