aboutsummaryrefslogtreecommitdiff
path: root/files/ca/web/css/_colon_only-child/index.html
blob: 43d5ef0a2afe239db5d1c367546b65c30a4744b4 (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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
---
title: ':only-child'
slug: 'Web/CSS/:only-child'
tags:
  - CSS
  - Layout
  - Pseudo-class
  - Reference
  - Web
translation_of: 'Web/CSS/:only-child'
---
<div>{{CSSRef}}</div>

<p>La <a href="/en-US/docs/CSS/Pseudo-classes" title="Pseudo classes">pseudo-class </a><a href="https://developer.mozilla.org/en-US/docs/Web/CSS">CSS</a> <strong><code>:only-child</code></strong> representa un element sense germans. És el mateix que <code>:first-child:last-child</code> o <code>:nth-child(1):nth-last-child(1)</code>, però amb una menor especificitat.</p>

<pre class="brush: css no-line-numbers">/* <span id="result_box" lang="ca"><span>Selecciona cada &lt;p&gt;, però només si és l'únic fill del seu pare</span></span> */
p:only-child {
  background-color: lime;
}</pre>

<div class="note">
<p><strong>Nota</strong>: Com es va definir originalment, l'element seleccionat havia de tenir un pare. A partir dels Selectores Nivell 4, això ja no és necessari.</p>
</div>

<h2 id="Sintaxi">Sintaxi</h2>

{{csssyntax}}

<h2 id="Exemples">Exemples</h2>

<h3 id="Exemple_bàsic">Exemple bàsic</h3>

<h4 id="HTML">HTML</h4>

<pre class="brush: html">&lt;main&gt;
  &lt;div&gt;
    &lt;i&gt;I am a lonely only child.&lt;/i&gt;
  &lt;/div&gt;

  &lt;div&gt;
    &lt;i&gt;I have siblings.&lt;/i&gt;&lt;br&gt;
    &lt;b&gt;So do I!&lt;/b&gt;&lt;br&gt;
    &lt;span&gt;I also have siblings, &lt;span&gt;but this is an only child.&lt;/span&gt;&lt;/span&gt;
  &lt;/div&gt;
&lt;/main&gt;</pre>

<h4 id="CSS">CSS</h4>

<pre class="brush: css">main :only-child {
  color: red;
}
</pre>

<h4 id="Resultat">Resultat</h4>

<p>{{EmbedLiveSample('Basic_example','100%',180)}}</p>

<h3 id="Un_exemple_de_llista"><span class="short_text" id="result_box" lang="ca"><span>Un exemple de llista</span></span></h3>

<h4 id="HTML_2">HTML</h4>

<pre class="brush: html">&lt;ol&gt;
  &lt;li&gt;First
    &lt;ul&gt;
      &lt;li&gt;This list has just one element.
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;Second
    &lt;ul&gt;
      &lt;li&gt;This list has three elements.
      &lt;li&gt;This list has three elements.
      &lt;li&gt;This list has three elements.
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;ol&gt;
</pre>

<h4 id="CSS_2">CSS</h4>

<pre class="brush: css">li li {
  list-style-type: disc;
}
li:only-child {
  color: red;
  list-style-type: square;
}</pre>

<h4 id="Resultat_2">Resultat</h4>

<p>{{EmbedLiveSample('A_list_example', '100%', 210)}}</p>

<h2 id="Especificacions">Especificacions</h2>

<table class="standard-table">
 <thead>
  <tr>
   <th scope="col">Especificació</th>
   <th scope="col">Estat</th>
   <th scope="col">Comentari</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td>{{SpecName('CSS4 Selectors', '#only-child-pseudo', ':only-child')}}</td>
   <td>{{Spec2('CSS4 Selectors')}}</td>
   <td><span id="result_box" lang="ca"><span>No es requereix que els elements coincidents tinguin un pare.</span></span></td>
  </tr>
  <tr>
   <td>{{SpecName('CSS3 Selectors', '#only-child-pseudo', ':only-child')}}</td>
   <td>{{Spec2('CSS3 Selectors')}}</td>
   <td>Definició inicial.</td>
  </tr>
 </tbody>
</table>

<h2 id="Navegadors_compatibles">Navegadors compatibles</h2>

<div>{{CompatibilityTable}}</div>

<div id="compat-desktop">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Descripció</th>
   <th>Chrome</th>
   <th>Edge</th>
   <th>Firefox (Gecko)</th>
   <th>Internet Explorer</th>
   <th>Opera</th>
   <th>Safari</th>
  </tr>
  <tr>
   <td>Suport bàsic</td>
   <td>2</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatGeckoDesktop(1.8)}}</td>
   <td>9</td>
   <td>{{CompatOpera(9.5)}}</td>
   <td>3.1</td>
  </tr>
  <tr>
   <td>No es requereix cap pare</td>
   <td>{{CompatChrome(57)}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatOpera(44)}}</td>
   <td>{{CompatUnknown}}</td>
  </tr>
 </tbody>
</table>
</div>

<div id="compat-mobile">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Descripció</th>
   <th>Android Webview</th>
   <th>Chrome for Android</th>
   <th>Edge</th>
   <th>Firefox Mobile (Gecko)</th>
   <th>IE Mobile</th>
   <th>Opera Mobile</th>
   <th>Safari Mobile</th>
  </tr>
  <tr>
   <td>Suport bàsic</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatGeckoMobile(1.8)}}</td>
   <td>9</td>
   <td>{{CompatOperaMobile(10)}}</td>
   <td>3.1</td>
  </tr>
  <tr>
   <td>No es requereix cap pare</td>
   <td>{{CompatChrome(57)}}</td>
   <td>{{CompatChrome(57)}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatOperaMobile(44)}}</td>
   <td>{{CompatUnknown}}</td>
  </tr>
 </tbody>
</table>
</div>

<h2 id="Vegeu_també">Vegeu també</h2>

<ul>
 <li>{{Cssxref(":only-of-type")}}</li>
 <li>{{Cssxref(":first-child")}}</li>
 <li>{{Cssxref(":last-child")}}</li>
 <li>{{Cssxref(":nth-child")}}</li>
</ul>