概要
:empty 疑似クラスは、如何なる子要素や文字(※半角スペースなども文字に含まれる)を持たない空の要素にのみマッチします。但し、コメント構文は判定に影響しません。
構文
<element>:empty { style properties }
例
.box {
background: red;
height: 200px;
width: 200px;
}
.box:empty {
background: lime;
}
<div class="box"><!-- この要素はコメントしか持たず、子要素が無いのでライム色になります --></div> <div class="box">この要素は空要素ではないので赤になります</div>
仕様
| 仕様書 | 策定状況 | コメント |
|---|---|---|
| Selectors Level 4 The definition of ':empty' in that specification. |
草案 | 変更無し |
| Selectors Level 3 The definition of ':empty' in that specification. |
勧告 | 最初期の定義 |
ブラウザ実装状況
| 機能 | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
|---|---|---|---|---|---|
| 基本サポート | 1.0 | 1.0 (1.7 or earlier) | 9.0 | 9.5 | 3.1 |
| 機能 | Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
|---|---|---|---|---|---|
| 基本サポート | 2.1 | 1.0 (1) | 9.5 | 10.0 | 3.1 |