It seems that there was an error in your code. Using <p class="badChild"/>
is incorrect because <p>
is a block element and should be closed like this:
<p class="badChild"></p>
. I have made the necessary updates to the question. Regarding your issue, unfortunately, CSS alone does not provide a way to select parent elements; you would need to use JavaScript or jQuery.
If there were a method to achieve this in CSS, it would likely be included in either of the current CSS selector specifications:
The Selectors Level 4 Working Draft introduces a :has()
pseudo-class, similar to the jQuery implementation. However, as of 2015, this feature is not supported by any browser.
Using :has()
, the original problem could be addressed like this:
li:has(> a.active) { /* styles for the li tag */ }
For now, if you require selecting a parent element, you will need to use JavaScript:
$(document).ready(function(){
$('.badChild').parent('.parent').hide();
});