Target first level
  • s and not the nested
  • s
  • 后端 未结 6 1144
    无人共我
    无人共我 2020-12-07 19:51

    I have the following HTML:

    • A
      • subsection
    • B <
    6条回答
    •  谎友^
      谎友^ (楼主)
      2020-12-07 20:42

      Have a container

      with a class, and use the > selector. Lets say your container div's class is "myclass":

      .myclass ul li {
         ...this will affect both levels of li.
      }
      
      .myclass > ul > li {
         ...this will only affect the first level.
      }
      
      .myclass > ul > li > ul > li {
         ...this will only affect the second level.
      }
      

      Note: the > selector does not work in IE6 and below when used as a CSS selector. It does work in all other browsers though, including IE7 and IE8, and when used in JQuery, it works in all browsers supported by jQuery, including IE6.

    提交回复
    热议问题