Laying <li> inside another <li>?

I have the following:

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

I want to style fooitem elements differently than grokitem elements:

#foo li {
  background-color: red;
}

.grok li {
  background-color: green;
}

but the definition of #foo li overrides the definition of .grok li, so everyone appears in red. How to define a style for grok items?

thank

+3
source share
5 answers

You need a slightly different style rule (currently the first, with an identifier, has a higher level of detail).
You can enable it as follows:

#foo li {
  background-color: red;
}

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

You can try here

+6
source

You can do this by creating a more specific rule:

#foo li {
    background-color: red;
}

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

li, , , :

ul.grok li.grokitem
{
    /* your styles here */
}
0
#foo li {
  background-color: red;
}

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

You do not need 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
0
source

Source: https://habr.com/ru/post/1762665/


All Articles