CSS selector for something not inside something else

后端 未结 3 562
太阳男子
太阳男子 2020-12-30 23:48

I have some nested elements like this:

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-31 00:14

    A little bit late to the party, and it might not match your use case, but this is what I ended up doing:

    HTML:

    CSS:

    .select-inside-this .select-this {
        background: blue;
    }
    .select-inside-this .not-inside-this .select-this {
        background: none;
    }
    

    The trick is to positively select the negative element and just undo the style.

    It'll work for simple use cases, at the very least.

提交回复
热议问题