:empty
:empty选择器选择每个没有任何子级的元素(包括文本节点)。
语法
<element>:empty { /* style properties */ }
值
例子
HTML
<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>
CSS
.box {
background: red;
height: 40px;
width: 100px;
text-align:center;
}
.box:empty {
background: green;
}
执行结果
I will be red