DEV Community

Cover image for Use :empty pseudo-class select dom in css
mixbo
mixbo

Posted on

1 1

Use :empty pseudo-class select dom in css

Alt Text

:empty pseudo-class selector can used when you need select empty dom in CSS let's show case

<!-- will be selector -->
<div></div>
<div></div>
<div><!-- comment --></div>

<!-- will not selected if has comment with line break  -->
<div>
  <!-- comment here  -->
</div>

<!-- will not be select if contain space -->
<div> </div>

<!-- not be select if contain content-->
<div> anything </div>

<!-- will be selector -->
<div></div>
Enter fullscreen mode Exit fullscreen mode

:empty just used for select DOM which contain nothing even comment.

demo

Hope it can help you :)

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

AWS GenAI LIVE!

GenAI LIVE! is a dynamic live-streamed show exploring how AWS and our partners are helping organizations unlock real value with generative AI.

Tune in to the full event

DEV is partnering to bring live events to the community. Join us or dismiss this billboard if you're not interested. ❤️