CSS3 :empty 选择器
指定空的p元素的背景色:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style>
p:empty {
width: 100px;
height: 20px;
background: #ff0000;
}
</style>
</head>
<body>
<p></p>
<p>A paragraph.</p>
<p>Another paragraph.</p>
</body>
</html>
定义和用法
:empty选择器选择每个没有任何子级的元素(包括文本节点)。
浏览器支持
表格中的数字表示支持该属性的第一个浏览器版本号。
| 选择器 | |||||
|---|---|---|---|---|---|
| :empty | 4.0 | 9.0 | 3.5 | 3.2 | 9.6 |
完整CSS选择器参考手册