I am trying to do is develop a CSS-stylsheet, that gets applied to all elements inside an element with a specific class - so far, no problem. But I need (to make it compatible with other stylesheets such as bootstrap) the possibility to set a new container element, like the one that applied the styles, inside the first container, that "resets" the values from my stylesheet.
Of course, a CSS reset isn't possible with current (-ly supported) versions. So I need to add something like a negative selector to all my selectors.
.jj-style-container:not(.jj-ignore) p.success-on-styled,
.jj-style-container:not(.jj-ignore):not(.jj-ignore) p.success-on-styled,
p.success-on-notStyled {
color: #0f0;
}
.jj-style-container:not(.jj-ignore) p.success-on-styled:before,
.jj-style-container:not(.jj-ignore):not(.jj-ignore) p.success-on-styled:before,
p.success-on-notStyled:before {
content: "SUCCESS!";
}
.jj-style-container:not(.jj-ignore) p.success-on-notStyled,
.jj-style-container:not(.jj-ignore):not(.jj-ignore) p.success-on-notStyled,
p.success-on-styled {
color: #f00;
}
.jj-style-container:not(.jj-ignore) p.success-on-notStyled:before,
.jj-style-container:not(.jj-ignore):not(.jj-ignore) p.success-on-notStyled:before,
p.success-on-styled:before {
content: "FAILURE :( Either styled although not wanted, or not styled, although wanted.";
}
<!DOCTYPE html>
<html>
<head>
<title>Negator-Test</title>
<link rel="stylesheet" type="text/css" href="../css/jj-styles-neg.css">
</head>
<body>
<div class="jj-style-container">
<p class="success-on-styled"></p>
<div>
<p class="success-on-styled"></p>
</div>
<div class="jj-ignore">
<p class="success-on-notStyled"></p>
</div>
</div>
<div class="jj-style-container jj-ignore">
<p class="success-on-notStyled"></p>
<div>
<p class="success-on-notStyled"></p>
</div>
<div class="jj-style-container">
<p class="success-on-styled"></p>
</div>
</div>
<p class="success-on-notStyled"></p>
</body>
</html>
And I am wondering, why this does not capture the elements in a div with class="success-on-notStyled". The styles get applied to all elements that are children of a container with class="jj-style-container", though, so that part works. I don't want to rewrite the bootstrap code into mine though, and the styles of all other stylesheets that should be supported. Mine should just support the styles, but not the functionality that for example Bootstrap adds. I know I could re-define the styles, but that would mean far more could and a double-override of styles just to get back to the original styles, but that adds a lot of bloat.
Because it was marked as duplicate for css3 not selector to test parent class:
The given solution of that question is what I tried in my code sample above via the
.style-applier :not(.style-resetter)
selector. Apparently that doesn't work for some reason though. Any ideas why? The elements in the sub-div are still affected of the styles defined in my stylesheet.