I have the following element structure:
<div class="general">
<div class="general-container">
<div class="general-grid">
<div class="general-wrapper"></div>
</div>
</div>
</div>
I’m trying to not display the general div when the general-wrapper is not having any child elements.
So first tried this:
.general-wrapper:not(:has(*)) {
background-color:red;
}
Which works.
Then this:
.general-container:has( .general-wrapper ) {
background-color:green;
}
Which also works.
But when I combine them it doesn’t.
.general-container:has( .general-wrapper:not(:has(*) ) ) {
display:none; // it does display, while it should not :(
}
codepen link:
https://codepen.io/Redox-FGL/pen/LYKgZzq
What I’m doing wrong or not getting?
Note: not looking for a solution with empty, there are more variables here and empty is not working. Need to check on child elements.
2
Answers
Do this instead:
You can set general-container to display none and then set it to display block, for example, if the wrapper has content.