首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

:empty

:empty伪类代表没有子节点的所有元素。这里只考虑元素节点和文本(包括空格)。注释或处理指令不影响元素是否被认为是空的。

代码语言:javascript
复制
/* Selects any <div> that contains no content */
div:empty {
  background: lime;
}

语法

代码语言:javascript
复制
:empty

实例

代码语言:javascript
复制
body {
  display: flex;
  justify-content: space-around;
}

.box {
  background: red;
  height: 100px;
  width: 100px;
}

.box:empty {
  background: lime;
}
代码语言:javascript
复制
<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 4The definition of ':empty' in that specification.

Working Draft

No change

Selectors Level 3The definition of ':empty' in that specification.

Recommendation

Initial definition

浏览器兼容性

Feature

Chrome

Edge

Firefox (Gecko)

Internet Explorer

Opera

Safari

Basic support

1.0

(Yes)

1.0 (1.7 or earlier)

9.0

9.5

3.1

Feature

Android

Edge

Firefox Mobile (Gecko)

IE Mobile

Opera Mobile

Safari Mobile

Basic support

2.1

(Yes)

1.0 (1)

9.5

10.0

3.1

扫码关注腾讯云开发者

领取腾讯云代金券