aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/css/general_sibling_combinator/index.html
blob: 941e9c9218a4a89e440eea7cea732e13ef161c44 (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
---
title: 通用兄弟选择器
slug: Web/CSS/General_sibling_combinator
tags:
  - CSS
  - Selectors
translation_of: Web/CSS/General_sibling_combinator
---
<div>{{CSSRef}}</div>

<h2 id="Summary" name="Summary">概述</h2>

<p><font face="Lucida Grande, Lucida Sans Unicode, DejaVu Sans, Lucida, Arial, Helvetica, sans-serif">兄弟选择符,位置无须紧邻,只须同层级,</font><code>A~B</code> 选择<code>A</code>元素之后所有同层级<code>B</code>元素。</p>

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

<pre class="syntaxbox notranslate">former_element ~ target_element { <em>style properties</em> }</pre>

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

<pre class="brush: css">p ~ span {
  color: red;
}</pre>

<p>上面的CSS作用于下面的HTML中:</p>

<pre class="brush: html">&lt;span&gt;This is not red.&lt;/span&gt;
&lt;p&gt;Here is a paragraph.&lt;/p&gt;
&lt;code&gt;Here is some code.&lt;/code&gt;
&lt;span&gt;And here is a span.&lt;/span&gt;</pre>

<p>则会产生下面的效果:</p>

<p>This is not red.</p>

<p>Here is a paragraph.</p>

<p><code>Here is some code.</code><span style="color: red;">And here is a span.</span></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><a class="external" href="http://www.w3.org/TR/css3-selectors/#general-sibling-combinators" title="http://www.w3.org/TR/css3-selectors/#general-sibling-combinators">CSS Selectors Level 3</a></td>
   <td>{{Spec2('CSS3 Selectors')}}</td>
   <td></td>
  </tr>
 </tbody>
</table>

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

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

<div id="compat-mobile"></div>

<h2 id="相关">相关</h2>

<ul>
 <li>{{Cssxref("Adjacent_sibling_selectors", "Adjacent sibling selectors")}}</li>
</ul>

<div id="blbt-translation-icon" style="margin: 0px; padding: 0px; font-family: sans-serif; position: fixed; left: 261px; top: 233px; width: 20px; height: 20px; line-height: 20px; color: rgb(255, 255, 255); background-color: rgb(0, 0, 0);">
<div style="margin: 0px; padding: 0px; width: 20px; height: 20px; line-height: 20px; color: rgb(255, 255, 255); background-color: rgb(0, 0, 0);"></div>
</div>