General sibling selectors

  • Revision slug: CSS/General_sibling_selectors
  • Revision title: General sibling selectors
  • Revision id: 9084
  • Created:
  • Creator: FredB
  • Is current revision? No
  • Comment one or more formatting changes

Revision Content

{{ CSSRef() }}

Summary

The ~ combinator separates two selectors and matches the second element only if it is preceded by the first, and both share a common parent.

Syntax

element ~ element { style properties }

Examples

p ~ span {
  color: red;
}

...where...

  <p>Here is a paragraph.</p>
<code>Here is some code.</code>
<span>And here is a span.</span>

... should look like ...

Here is a paragraph

Here is some code.And here is a span.

Specifications

Specification Status Comment
CSS Selectors Level 3 {{ Spec2('CSS3 Selectors') }}  

Browser compatibility

{{ CompatibilityTable() }}

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support {{CompatUnknown()} {{ CompatGeckoDesktop("1") }} 7 9 3
Feature Firefox Mobile (Gecko) Android IE Phone Opera Mobile Safari Mobile
Basic support {{ CompatUnknown() }} {{ CompatUnknown() }} {{ CompatUnknown() }} {{ CompatUnknown() }} {{ CompatUnknown() }}

See Also

{{ Cssxref("Adjacent sibling selectors") }}

{{ languages( { "fr": "fr/CSS/Sélecteurs_de_voisins_généraux" }) }}

Revision Source

<p>{{ CSSRef() }}</p>
<h2 id="Summary" name="Summary">Summary</h2>
<p>The <code>~</code> combinator separates two selectors and matches the second element only if it is preceded by the first, and both share a common parent.</p>
<h2 id="Syntax" name="Syntax">Syntax</h2>
<pre class="eval">element ~ element { <em>style properties</em> }
</pre>
<h2 id="Examples" name="Examples">Examples</h2>
<pre class="brush: css">p ~ span {
  color: red;
}</pre>
<p>...where...</p>
<pre class="brush: html">  &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>... should look like ...</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">Specifications</h2>
<table class="standard-table"> <thead> <tr style="background-color: rgb(255, 204, 255);"> <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="Browser_compatibility">Browser compatibility</h2>
<p>{{ CompatibilityTable() }}</p>
<div id="compat-desktop"> <table class="compat-table"> <tbody> <tr> <th>Feature</th> <th>Chrome</th> <th>Firefox (Gecko)</th> <th>Internet Explorer</th> <th>Opera</th> <th>Safari</th> </tr> <tr> <td>Basic support</td> <td>{{CompatUnknown()}</td> <td>{{ CompatGeckoDesktop("1") }}</td> <td>7</td> <td>9</td> <td>3</td> </tr> </tbody> </table>
</div>
<div id="compat-mobile"> <table class="compat-table"> <tbody> <tr> <th>Feature</th> <th>Firefox Mobile (Gecko)</th> <th>Android</th> <th>IE Phone</th> <th>Opera Mobile</th> <th>Safari Mobile</th> </tr> <tr> <td>Basic support</td> <td>{{ CompatUnknown() }}</td> <td>{{ CompatUnknown() }}</td> <td>{{ CompatUnknown() }}</td> <td>{{ CompatUnknown() }}</td> <td>{{ CompatUnknown() }}</td> </tr> </tbody> </table>
</div>
<h2 id="See_Also">See Also</h2>
<p>{{ Cssxref("Adjacent sibling selectors") }}</p>
<p>{{ languages( { "fr": "fr/CSS/Sélecteurs_de_voisins_généraux" }) }}</p>
Revert to this revision