This page was translated from English by the community. Learn more and join the MDN Web Docs community.

View in English Always switch to English

:empty

Baseline Widely available *

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨июль 2015 г.⁩.

* Some parts of this feature may have varying levels of support.

Описание

Псевдокласс :empty находит любой элемент, у которого нет потомков. Учитываются элементы и текст (включая пробелы). Комментарии не повлияют на то, что элемент будет рассматриваться как не пустой.

Синтаксис

<element>:empty { /* стили */ } 

Примеры

css
.box { background: red; height: 200px; width: 200px; } .box:empty { background: lime; } 
html
<div class="box"><!-- Я буду лаймовым --></div> <div class="box">Я буду красным</div> <div class="box"> <!-- Я буду красным, так как перед комментарием стоят пробелы --> </div> 

Спецификации

Specification
Selectors Level 4
# the-empty-pseudo

Совместимость с браузерами