CSS selector for something not inside something else

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

I have some nested elements like this:

3条回答
  •  醉话见心
    2020-12-31 00:21

    You can use the Child Combinator Selector > to specify direct children:

    .select-inside-this :not(.not-inside-this) .select-this,
    .select-inside-this > .select-this {
        /* style here /*
    }
    

    This selects any .select-this element which is not a descendent of any .not-inside-this element and also selects .select-this elements which are direct children of .select-inside-this elements.

    body > .select-inside-this :not(.not-inside-this) .select-this,
    body > .select-inside-this > .select-this {
      color: red;
    }
    This should not be selected
    This should be selected
    This should not be selected

提交回复
热议问题