I am trying to target a paragraph only if it is not inside the custom component my-component. like this:
// Style all elements that are NOT inside my-component
:not(my-component) *{
color: red;
}
With the answer from @Frox we can see that we can target everything except the my-component container
body :not(my-component *) {
color: red
}
But if we specify one more level to target every p except the p inside my-component it's still selecting the p...
body :not(my-component *) p{
color: red
}
Can anyone explain why this isn't working or if it's a bug or if it's just not possible?
/* Style all elements that are descendants of body and NOT inside my-component */
body :not(my-component *) p{
color: red;
}
.container {
border: 1px solid #ccc;
padding: 10px;
margin-bottom: 20px;
}
<div class="container">
<p>This paragraph is outside the special container → should be <strong style="color:red;">RED</strong>.</p>
</div>
<my-component class="container">
<p>This paragraph is inside the special container → should be <strong >black</strong>.</p>
<span>Another span-element inside → black</span>
</my-component>
<div class="container">
<p>Another outside paragraph → RED</p>
<span>another span outsize my-component</span>
</div>
My final goal is to have a style rule that exempts part of the page but targets everything else.
:not(header) {
my-dropdown-component {}
}