mozilla

Revision 35194 of :only-child

  • Revision slug: CSS/:only-child
  • Revision title: :only-child
  • Revision id: 35194
  • Created:
  • Creator: FredB
  • Is current revision? No
  • Comment Reverted to earlier version; one or more formatting changes

Revision Content

Summary

The :only-child pseudo-class represents any element which is the only child of its parent.

Syntax

parent child:only-child {
    property:value;
} 

Examples

div span:only-child {
    color:red;
}
<div>
    <span>Some red text</span>
</div>

<div>
    <span>Some regular text</span>
    <span>Some regular text</span>
</div> 

Result

Some red text
Some regular text Some regular text

Specifications

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

Browser compatibility

{{ CompatibilityTable() }}

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support 2 {{ CompatGeckoDesktop("1") }} 9 9.5 3.1
Feature Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support 2.1 {{ CompatGeckoMobile("1") }} 9 10.0 3.1

Revision Source

<h3>Summary</h3>
<p>The <code>:only-child</code> <a href="/en/CSS/Pseudo-classes" title="Pseudo-classes">pseudo-class</a> represents any element which is the only child of its parent.</p><h3>Syntax</h3>
<pre>parent child:only-child {
    property:value;
} 
</pre>
<h3>Examples</h3>
<pre class="brush: css">div span:only-child {
    color:red;
}
</pre>
<pre class="brush: html">&lt;div&gt;
    &lt;span&gt;Some red text&lt;/span&gt;
&lt;/div&gt;

&lt;div&gt;
    &lt;span&gt;Some regular text&lt;/span&gt;
    &lt;span&gt;Some regular text&lt;/span&gt;
&lt;/div&gt; 
</pre>
<h4>Result</h4>
<pre class="eval"><div><span style="color:red;">Some red text</span></div><div><span>Some regular text</span> <span>Some regular text</span></div></pre>
<h2 name="Specifications">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/#only-child-pseudo" title="http://www.w3.org/TR/css3-selectors/#only-child-pseudo">CSS Selectors Level 3</a></td> <td>{{ Spec2('CSS3 Selectors') }}</td> <td> </td> </tr> </tbody>
</table>
<h3>Browser compatibility</h3>
<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>2</td> <td>{{ CompatGeckoDesktop("1") }}</td> <td>9</td> <td>9.5</td> <td>3.1</td> </tr> </tbody>
</table>
</div>
<div id="compat-mobile">
<table class="compat-table"> <tbody> <tr> <th>Feature</th> <th>Android</th> <th>Firefox Mobile (Gecko)</th> <th>IE Mobile</th> <th>Opera Mobile</th> <th>Safari Mobile</th> </tr> <tr> <td>Basic support</td> <td>2.1</td> <td>{{ CompatGeckoMobile("1") }}</td> <td>9</td> <td>10.0</td> <td>3.1</td> </tr> </tbody>
</table>
</div>
Revert to this revision