CSS :empty 选择器
实例
指定空的 p 元素的背景色:
<!DOCTYPE html><html><head><style>p:empty {width: 100px;height: 20px;background: #ff0000;}</style></head><body><p></p><p>一个段落</p><p>另一个段落</p></body></html>
浏览器支持
表格中的数字注明了完全支持该属性的首个浏览器版本。
| 选择器 | |||||
|---|---|---|---|---|---|
| :empty | 4.0 | 9.0 | 3.5 | 3.2 | 9.6 |
定义和用法
:empty 选择器匹配没有子元素(包括文本节点)的每个元素。