简介
:empty 伪类 代表没有子元素的元素。 这里说的子元素,只计算元素结点及文本(包括空格),注释、运行指令不考虑在内。
语法
<element>:empty { /* style properties */ }
例子
.box {
background: red;
height: 200px;
width: 200px;
}
.box:empty {
background: lime;
}
<div class="box"><!-- I will be lime --></div>
<div class="box">I will be red</div>
<div class="box">
<!-- I will be red because of the whitespace around this comment -->
</div>
细则
| Specification | Status | Comment |
|---|---|---|
| Selectors Level 4 :empty |
Working Draft | No change. |
| Selectors Level 3 :empty |
Recommendation | Initial definition. |
浏览器兼容
| Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
|---|---|---|---|---|---|
| Basic support | 1.0 | 1.0 (1.7 or earlier) | 9.0 | 9.5 | 3.1 |
| Feature | Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
|---|---|---|---|---|---|
| Basic support | 2.1 | 1.0 (1) | 9.5 | 10.0 | 3.1 |