I want to make the following inner span disappear, if it's an only child:
<div class="foo">
<span></span>
</div>
i.e. the selector should not work in this case:
<div class="foo">
<span></span>
Some text
</div>
I tried :only-child
and :last-child
which don't work, I assume because of that "Some text" text.
Adjacent Sibling Selector (+) The adjacent sibling selector is used to select an element that is directly after another specific element. Sibling elements must have the same parent element, and "adjacent" means "immediately following".
The :only-child CSS pseudo-class represents an element without any siblings. This is the same as :first-child:last-child or :nth-child(1):nth-last-child(1) , but with a lower specificity.
I think this cannot be done with only CSS. You should use jQuery or JavaScript by making some conditions.
if ($(".foo").text().length < 1 && $('.foo span').is(':empty')) {
//hide your element here
$('.foo').hide();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With