CSS :not() selector. Apply style if parent does not exist

后端 未结 2 1621
小鲜肉
小鲜肉 2021-01-04 19:51

I am trying to apply a style to a div based on its parent class. I am using the :not() selector to select the div whose parent is not .container1, the second di

2条回答
  •  执念已碎
    2021-01-04 20:08

    CSS can't do "parent lookups" like that. You would need to reverse the structure to something like:

    .my-container:not(.container1) .myDiv
    

    Granted, you would need to add the shared my-container class to all "parent" divs of interest.

提交回复
热议问题