I want to add content (with :before selector) only if span has value.
If the span is empty I don't want to add content with :before selector.
How can I do it with css?
<!DOCTYPE html>
<html>
<head>
<style>
span.b::before {
content: "\2022"
}
.span.b:empty {}
</style>
</head>
<body>
<div class="a">
<span class="b">AAA</span>
</div>
</body>
</html>
You were close. You're looking for:
span.b:not(:empty)::before {
content:"\2022"
}
span.b:not(:empty)::before {
content:"\2022"
}
<div class="a">
<span class="b">AAA</span>
</div>
<div class="a">
<span class="b"></span>
</div>
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