aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/css/_colon_empty/index.html
blob: a51ec68257d8668b24c0d48861ff134bd5cd87d2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
---
title: ':empty'
slug: 'Web/CSS/:empty'
tags:
  - ':empty'
  - CSS
  - CSS 骨架效果
  - CSS伪类
  - Layout
  - css skeleton
  - skelenton
  - 参考
  - 布局
  - 网络
translation_of: 'Web/CSS/:empty'
---
<div>{{ CSSRef()}}</div>

<p><code>:empty</code> <a href="https://developer.mozilla.org/en-US/docs/Web/CSS">CSS</a> <a href="/zh-CN/CSS/Pseudo-classes" title="Pseudo-classes">伪类</a> 代表没有子元素的元素。子元素只可以是元素节点或文本(包括空格)。注释或处理指令都不会产生影响。</p>

<pre class="brush: css no-line-numbers">/* Selects any &lt;div&gt; that contains no content */
div:empty {
  background: lime;
}</pre>

<h2 id="Syntax" name="Syntax">语法</h2>

<pre class="syntaxbox">{{csssyntax}}
</pre>

<h2 id="Examples" name="Examples">例子</h2>

<h3 id="HTML">HTML</h3>

<pre class="brush: html">&lt;div class="box"&gt;&lt;!-- I will be lime --&gt;&lt;/div&gt;
&lt;div class="box"&gt;I will be pink&lt;/div&gt;
&lt;div class="box"&gt;
    &lt;!-- I will be red because of the whitespace around this comment --&gt;
&lt;/div&gt;</pre>

<h3 id="CSS">CSS</h3>

<div class="hidden">
<pre class="brush: css">body {
  display: flex;
  justify-content: space-around;
}</pre>
</div>

<pre class="brush: css">.box {
    background: pink;
    height: 80px;
    width: 80px;
}

.box:empty {
    background: lime;
}
</pre>

<h3 id="Result">Result</h3>

<p>{{EmbedLiveSample('Examples', 300, 80)}}</p>

<h2 id="Specifications" name="Specifications">规范</h2>

<table class="standard-table">
 <thead>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td>{{ SpecName('CSS4 Selectors', '#empty-pseudo', ':empty') }}</td>
   <td>{{ Spec2('CSS4 Selectors') }}</td>
   <td>No change.</td>
  </tr>
  <tr>
   <td>{{ SpecName('CSS3 Selectors', '#empty-pseudo', ':empty') }}</td>
   <td>{{ Spec2('CSS3 Selectors') }}</td>
   <td>Initial definition.</td>
  </tr>
 </tbody>
</table>

<h2 id="浏览器兼容">浏览器兼容</h2>



<p>{{Compat("css.selectors.empty")}}</p>

<h2 id="参考">参考</h2>

<ul>
 <li>{{CSSxRef(":blank")}}</li>
</ul>

<h3 id="example">example</h3>

<p><a href="https://codepen.io/xgqfrms/full/zQEJWw">https://codepen.io/xgqfrms/full/zQEJWw</a></p>

<p> </p>