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

    I have the following HTML:

    • A
      • subsection
    • B <
    6条回答
    •  被撕碎了的回忆
      2020-12-07 20:42

      Here is an extended version of user @Spudley's answer - with a snippet.

      Might save some people some time.

      /* this will affect all levels of li */
      .myclass ul li {
        color: red;
      }
      
      
      /* this will only affect level 1 */
      .myclass>ul>li {
        color: green;
      }
      
      
      /* this will only affect level 2 */
      .myclass>ul>li>ul>li {
        color: blue;
      }
      
      
      /* this will only affect level 3 */
      .myclass>ul>li>ul>li>ul>li {
        color: aqua;
      }
      
      
      * {
        font-family: arial;
      }
      • Level 1
        • Level 2
          • Level 3
          • Level 3
        • Level 2
        • Level 2
          • Level 3
          • Level 3
          • Level 3
            • Level 4
            • Level 4
      • Level 1

    提交回复
    热议问题