Frost
Frost
KPCKevin Powell - Community
Created by Frost on 12/20/2023 in #front-end
How to select an element that doesn't have a child or contains a particular element
how can i select an element in css if it doesn't have or contain a particular element for example
<style>
/*
this is not selecting the category container if it doesn't have a child element with a class of category
*/
.category-container:has(>:not(.category)){
background-color:red;
}
</style>
<div class="category-container">
<div class="category"></div>
</div>
<style>
/*
this is not selecting the category container if it doesn't have a child element with a class of category
*/
.category-container:has(>:not(.category)){
background-color:red;
}
</style>
<div class="category-container">
<div class="category"></div>
</div>
i want to match an element with a class called
category-container
category-container
and doesn't have a child element with a class called
category
category
8 replies