Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using CSS to hide <span> elements when they are empty

I have this code:

<p class="alert-error">
<span></span>
<span></span>
<span></span>
</p>

I want to change the style of the CSS for "alert-error" when it shows <span></span>. The code is being generated by a system with limited backend customization. Sometimes the spans are filled with error messages.

The :empty selector doesn't seem to work cause I have to put it on the alert-error class.

Any help would be appreciated.

like image 695
closeyetfar Avatar asked Mar 25 '26 14:03

closeyetfar


1 Answers

I made the css like this:

.alert-error span:empty {
    background: green;
}

and it works, see jsfiddle

like image 164
Raphael Müller Avatar answered Mar 27 '26 04:03

Raphael Müller



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!