The :empty selector matches every element that has no children (including text nodes). This example specifies a background color for empty <p> elements:
HTML file: | Displayed by browser: |
---|---|
<style>
p:empty { width: 100px; height: 20px; background: #ff0000; } </style> <body> <p></p> <p>A paragraph.</p> <p>Another paragraph.</p> </body> |
A paragraph. Another paragraph. |