blob: 69aec535c7385af1ee429c84f233eeac038cdd6a (
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
106
107
108
109
|
---
title: 后代选择器
slug: Web/CSS/Descendant_combinator
tags:
- CSS
- Selectors
translation_of: Web/CSS/Descendant_combinator
---
<div>{{CSSRef("Selectors")}}</div>
<p><strong>后代组合器</strong>(通常用单个空格(<code> </code>)字符表示)组合了两个选择器,如果第二个选择器匹配的元素具有与第一个选择器匹配的祖先(父母,父母的父母,父母的父母的父母等)元素,则它们将被选择。利用后代组合器的选择器称为<dfn>后代选择器</dfn>。</p>
<pre class="brush: css no-line-numbers notranslate">/* List items that are descendants of the "my-things" list */
ul.my-things li {
margin: 2em;
}</pre>
<p>从技术上讲,后代组合器是两个选择器之间的一个或多个 {{Glossary("CSS")}} 空格字符-空格字符和/或四个控制字符之一:回车,换页,换行和制表符在没有其他组合器的情况下。此外,组成组合器的空白字符可以包含任意数量的CSS注释。</p>
<h2 id="语法">语法</h2>
<pre class="syntaxbox notranslate"><var>selector1</var> <var>selector2</var> {
<var>/* property declarations */</var>
}</pre>
<h2 id="Examples">Examples</h2>
<h3 id="CSS">CSS</h3>
<pre class="brush: css notranslate">li {
list-style-type: disc;
}
li li {
list-style-type: circle;
}
</pre>
<h3 id="HTML">HTML</h3>
<pre class="brush: html notranslate"><ul>
<li>
<div>Item 1</div>
<ul>
<li>Subitem A</li>
<li>Subitem B</li>
</ul>
</li>
<li>
<div>Item 2</div>
<ul>
<li>Subitem A</li>
<li>Subitem B</li>
</ul>
</li>
</ul>
</pre>
<h3 id="Result">Result</h3>
<p>{{EmbedLiveSample("Examples", "100%", 160)}}</p>
<h2 id="规范">规范</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", "#descendant-combinators", "descendant combinator")}}</td>
<td>{{Spec2("CSS4 Selectors")}}</td>
<td></td>
</tr>
<tr>
<td>{{SpecName("CSS3 Selectors", "#descendant-combinators", "descendant combinator")}}</td>
<td>{{Spec2("CSS3 Selectors")}}</td>
<td></td>
</tr>
<tr>
<td>{{SpecName("CSS2.1", "selector.html#descendant-selectors", "descendant selectors")}}</td>
<td>{{Spec2("CSS2.1")}}</td>
<td></td>
</tr>
<tr>
<td>{{SpecName("CSS1", "#contextual-selectors", "contextual selectors")}}</td>
<td>{{Spec2("CSS1")}}</td>
<td>Initial definition</td>
</tr>
</tbody>
</table>
<h2 id="浏览器兼容性">浏览器兼容性</h2>
<p>{{Compat("css.selectors.descendant")}}</p>
<h2 id="相关">相关</h2>
<ul>
<li><a href="/en-US/docs/Web/CSS/Child_combinator">Child combinator</a></li>
</ul>
|