--- title: ':only-child' slug: 'Web/CSS/:only-child' tags: - CSS - CSS Pseudo-Klasse - Layout - Referenz - Selektoren - Web translation_of: 'Web/CSS/:only-child' --- <div>{{CSSRef}}</div> <h2 id="Übersicht">Übersicht</h2> <p>Die <span style="line-height: 1.5;">CSS </span><a href="/en-US/docs/CSS/Pseudo-classes" style="line-height: 1.5;" title="Pseudo-classes">Pseudo-Klasse</a><span style="line-height: 1.5;"> </span><code style="font-style: normal; line-height: 1.5;">:only-child</code><span style="line-height: 1.5;"> </span><span style="line-height: 1.5;"> repräsentiert ein Element, welches das einzige Kindeelement innerhalb seines Elternelementes ist. Das ist das gleiche wie </span><code style="font-style: normal; line-height: 1.5;">:first-child:last-child</code><span style="line-height: 1.5;"> oder </span><code style="font-style: normal; line-height: 1.5;">:nth-child(1):nth-last-child(1)</code><span style="line-height: 1.5;">, nur mit einer geringeren Spezifizität.</span></p> <h2 id="Syntax">Syntax</h2> <pre class="syntaxbox">parent child:only-child { property: value; } </pre> <h2 id="Beispiele">Beispiele</h2> <h3 id="Einfaches_Beispiel">Einfaches Beispiel</h3> <pre class="brush: css">span:only-child { color: red; } </pre> <pre class="brush: html"><div> <span>Dieser span ist das einzige Kind seines Elternteils</span> </div> <div> <span><span style="font-size: 1rem;">Dieser span ist eines von zwei Kindern seines Elternteils</span><span style="font-size: 1rem;"></span></span> <span><span style="font-size: 1rem;">Dieser span ist eines von zwei Kindern seines Elternteils</span><span style="font-size: 1rem;"></span></span> </div> </pre> <h4 id="Ergebnis">Ergebnis</h4> <p>{{EmbedLiveSample('Basic_example', '100%', 100)}}</p> <h3 id="Ein_Beispiel_für_Listen">Ein Beispiel für Listen</h3> <pre class="brush: css">li li { list-style-type: disc; } li:only-child { color: #6699ff; font-style: italic; list-style-type: square; }</pre> <pre class="brush: html"><ol> <li>Erstens <ul> <li>Einziges Kind </ul> </li> <li>Zweitens <ul> <li>Diese Liste hat zwei Elemente <li><span style="font-size: 1rem;">Diese Liste hat zwei Elemente</span> </ul> </li> <li>Drittens <ul> <li><span style="font-size: 1rem;">Diese Liste hat drei Elemente</span> <li><span style="font-size: 1rem;">Diese Liste hat drei Elemente</span> <li><span style="font-size: 1rem;">Diese Liste hat drei Elemente</span> </ul> </li> <ol> </pre> <h4 id="Ergebnis_2">Ergebnis</h4> <p>{{EmbedLiveSample('A_list_example', '100%', 150)}}</p> <hr> <h2 id="Spezifizierungen">Spezifizierungen</h2> <table class="standard-table"> <thead> <tr> <th scope="col">Spezifizierung</th> <th scope="col">Status</th> <th scope="col">Kommentar</th> </tr> </thead> <tbody> <tr> <td>{{SpecName('CSS4 Selectors', '#only-child-pseudo', ':only-child')}}</td> <td>{{Spec2('CSS4 Selectors')}}</td> <td>Keine Änderung.</td> </tr> <tr> <td>{{SpecName('CSS3 Selectors', '#only-child-pseudo', ':only-child')}}</td> <td>{{Spec2('CSS3 Selectors')}}</td> <td>Ausgangs-Definition.</td> </tr> </tbody> </table> <h2 id="Browser-Kompatibilität">Browser-Kompatibilität</h2> {{Compat("css.selectors.only-child")}}