Add CSS style to the parent(without .second-stage class) of .apply-style-here using CSS only

Welcome to our community

Be apart of something great, join today!

KennethJer

Newbie
Messages
5
Reaction score
2
Points
3
Hello,

How can I apply a style to the parent div of .apply-style-here styles by meeting only this condition Parent of .apply-style-here should be a plain div or without the .second-stage class .apply-style-here parent's parent should not have a .second-stage

You don't have permission to view the spoiler content. Log in or register now.

Thank you
 

RidgeOa

Newbie
Messages
7
Reaction score
1
Points
3
You can try this:

CSS:
/* 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;
}

Remember that Firefox hasn't adapted has() yet :)

CSS:
first-stage div:not(.second-stage):has(.apply-style-here) {
    border: 1px solid blue;
}
 
  • Advertisement
  • Advertisement

    Top