aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/css/adjacent_sibling_combinator/index.html
blob: fdd38fc36074fcf08ac804fbdee841b7791ce401 (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
---
title: 相邻兄弟选择器
slug: Web/CSS/Adjacent_sibling_combinator
tags:
  - CSS
  - Selectors
translation_of: Web/CSS/Adjacent_sibling_combinator
---
<div>{{CSSRef("Selectors")}}</div>

<p><strong>相邻兄弟选择器</strong> (<code>+</code>) 介于两个选择器之间,当第二个元素<em>紧跟在</em>第一个元素之后,并且两个元素都是属于同一个父{{domxref("元素")}}的子元素,则第二个元素将被选中。</p>

<pre class="brush: css no-line-numbers">/* 图片后面紧跟着的段落将被选中 */
img + p {
  font-style: bold;
}</pre>

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

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

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

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

<pre class="brush: css">li:first-of-type + li {
  color: red;
}
</pre>

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

<pre class="brush: html">&lt;ul&gt;
  &lt;li&gt;One&lt;/li&gt;
  &lt;li&gt;Two!&lt;/li&gt;
  &lt;li&gt;Three&lt;/li&gt;
&lt;/ul&gt;</pre>

<h3 id="结果">结果</h3>

<ul>
 <li>One</li>
 <li style="color: red;">Two!</li>
 <li>Three</li>
</ul>

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

<table class="standard-table">
 <thead>
  <tr>
   <th scope="col">规范</th>
   <th scope="col">状态</th>
   <th scope="col">备注</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td>{{SpecName('CSS4 Selectors', '#adjacent-sibling-combinators', 'next-sibling combinator')}}</td>
   <td>{{Spec2('CSS4 Selectors')}}</td>
   <td>重命名为: "next-sibling" combinator。</td>
  </tr>
  <tr>
   <td>{{SpecName('CSS3 Selectors', '#adjacent-sibling-combinators', 'Adjacent sibling combinator')}}</td>
   <td>{{Spec2('CSS3 Selectors')}}</td>
   <td></td>
  </tr>
  <tr>
   <td>{{SpecName('CSS2.1', 'selector.html#adjacent-selectors', 'Adjacent sibling selectors')}}</td>
   <td>{{Spec2('CSS2.1')}}</td>
   <td>初始定义。</td>
  </tr>
 </tbody>
</table>

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

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

<h2 id="See_also" name="See_also">参阅</h2>

<ul>
 <li><a href="/zh-CN/docs/Web/CSS/General_sibling_selectors">通用兄弟选择器</a></li>
</ul>