The :empty
pseudo-class selects the selector element with no elements or text node (including whitespace).
selector:empty{
background-color: pink;
}
Here are some of the cases where an element is considered empty:
<p></p>
<p><!-- I'm an empty element. --></p>
Here are some of the cases where an element is considered empty:
<p>Non-empty</p>
<p>
<span> non-empty</span>
</p>
<p> </p>
<p>
<!-- The white space(new line and tab space) around this comment makes its parent as a "non-empty" element -->
</p>
In the above code, we have set a pink background for empty blocks and a deeppink background for non-empty blocks using the :empty
pseudo-class.