aboutsummaryrefslogtreecommitdiff
path: root/files/ca/web/css/_colon_focus-within/index.html
blob: ae6393853d13c0b23ddbde9687ab0e6e644def30 (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
---
title: ':focus-within'
slug: 'Web/CSS/:focus-within'
tags:
  - CSS
  - Layout
  - Pseudo-class
  - Reference
  - Web
translation_of: 'Web/CSS/:focus-within'
---
<div>{{CSSRef}}</div>

<p>La <a href="/en-US/docs/Web/CSS/Pseudo-classes">pseudo-class</a> <a href="/en-US/docs/Web/CSS">CSS</a> <strong><code>:focus-within</code></strong> representa un element que ha rebut focus o <em>conté</em> un element que ha rebut focus. En altres paraules, representa un element que està aparellat amb la pseudo-class {{cssxref(":focus")}} o té un descendent que està aparellat amb <code>:focus</code>. (Això inclou descendents en <a href="/en-US/docs/Web/Web_Components/Shadow_DOM">arbres d'ombres</a>.)</p>

<pre class="brush: css no-line-numbers">/* <span id="result_box" lang="ca"><span>Selecciona un &lt;div&gt; quan un dels seus descendents està enfocat</span></span> */
div:focus-within {
  background: cyan;
}</pre>

<p>Aquest selector és útil, per fer un exemple comú, per a ressaltar un contenidor complet {{htmlElement("form")}} quan l'usuari se centra en un dels seus camps {{htmlElement("input")}}.</p>

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

<pre class="syntaxbox">{{csssyntax}}</pre>

<h2 id="Exemple">Exemple</h2>

<p>En aquest exemple, el formulari rebrà estils de color especials quan l'entrada de text rep el focus.</p>

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

<pre class="brush: html">&lt;p&gt;Try typing into this form.&lt;/p&gt;

&lt;form&gt;
  &lt;label for="given_name"&gt;Given Name:&lt;/label&gt;
  &lt;input id="given_name" type="text"&gt;
  &lt;br&gt;
  &lt;label for="family_name"&gt;Family Name:&lt;/label&gt;
  &lt;input id="family_name" type="text"&gt;
&lt;/form&gt;</pre>

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

<pre class="brush: css">form {
  border: 1px solid;
  color: gray;
  padding: 4px;
}

form:focus-within {
  background: #ff8;
  color: black;
}

input {
  margin: 4px;
}
</pre>

<h3 id="Resultat">Resultat</h3>

<p>{{EmbedLiveSample("Example", 500, 150)}}</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", "#the-focus-within-pseudo", ":focus-within")}}</td>
   <td>{{Spec2("CSS4 Selectors")}}</td>
   <td>Definició inicial</td>
  </tr>
 </tbody>
</table>

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

<p>{{CompatibilityTable}}</p>

<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>{{CompatChrome("60")}}</td>
   <td>{{CompatNo}}<sup>[1]</sup></td>
   <td>{{CompatGeckoDesktop("52.0")}}<sup>[2]</sup></td>
   <td>{{CompatNo}}</td>
   <td>{{CompatOpera("47")}}</td>
   <td>10.1</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>Firefox Mobile (Gecko)</th>
   <th>IE Mobile</th>
   <th>Opera Mobile</th>
   <th>Safari Mobile</th>
  </tr>
  <tr>
   <td>Suport bàsic</td>
   <td>{{CompatChrome("60")}}</td>
   <td>{{CompatChrome("60")}}</td>
   <td>{{CompatGeckoMobile("52.0")}}<sup>[2]</sup></td>
   <td>{{CompatNo}}</td>
   <td>{{CompatOpera("47")}}</td>
   <td>10.3</td>
  </tr>
 </tbody>
</table>
</div>

<p>[1] Aquesta característica encara no està implementada. Consulteu la <a href="https://wpdev.uservoice.com/forums/257854-microsoft-edge-developer/suggestions/11725071-implement-focus-within-from-selectors-4">sol·licitud de millora relacionada</a>.</p>

<p>[2] Aquesta característica es va implementar al {{bug("1176997")}}.</p>

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

<ul>
 <li>{{cssxref(":focus")}}</li>
</ul>