Using only css, add the css style to the parent of .apply-style-here (without the .second-stage class)-PHP Chinese Network Q&A
Using only css, add the css style to the parent of .apply-style-here (without the .second-stage class)
P粉798010441
P粉798010441 2023-09-11 14:23:08
0
1
483

How to apply styles to the parent div of .apply-style-here by only meeting this condition

  1. The parent of .apply-style-here should be a normal div or no .second-stage class
  2. .apply-style-here Parent's parent should not have .second-stage Thanks
Content
Content
Content

Try solutions

/* Result: Put border to all parent of apply-style-here class */ .first-stage:has(div > .apply-style-here) > div { /* margin-top: 20px; */ border: 1px solid red; } /* Result: No styles applied at all */ .first-stage:not('div > .second-stage') > div { border: 1px solid blue; } /* Result: No styles applied at all */ .first-stage:has(div:not('.second-stage') > .apply-style-here) > div { border: 1px solid blue; } /* Result: Applied to all .apply-style-here even second .second-stage is present */ .first-stage:has(div:not(.second-stage) > .apply-style-here) > div { border: 1px solid blue; } /* Result: Applied to all .apply-style-here even second .second-stage is present */ .first-stage:has(div:not(.second-stage > .apply-style-here)) > div { border: 1px solid blue; }

P粉798010441
P粉798010441

reply all (1)
P粉814160988

According to your description, the following selectors may work:

:not(.second-stage) > :not(.second-stage) > .apply-style-here

:not(.second-stage) > :not(.second-stage) > .apply-style-here { border: solid 1px blue; }
Content
Content
Content
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!