aboutsummaryrefslogtreecommitdiff
path: root/files/fr/web/css/_colon_placeholder-shown/index.html
blob: 943598fde4c204e652a4a016f7ec5128530f6dbf (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
199
---
title: ':placeholder-shown'
slug: 'Web/CSS/:placeholder-shown'
tags:
  - CSS
  - Pseudo-classe
  - Reference
translation_of: 'Web/CSS/:placeholder-shown'
---
<div>{{CSSRef}}</div>

<p>La <a href="/fr/docs/Web/CSS/Pseudo-classes">pseudo-classe</a> <strong><code>:placeholder-shown</code></strong> permet de représenter n'importe quel élément {{htmlElement("input")}} ou {{htmlElement("textarea")}} affichant <a href="/fr/docs/Web/Guide/HTML/Forms_in_HTML#The_placeholder_attribute">un texte de substitution</a>.</p>

<pre class="brush: css no-line-numbers">/* Cible tout élément &lt;input&gt; ou &lt;textarea&gt; avec un */
/* attribut placeholder actuellement affiché        */
:placeholder-shown {
  border: 2px solid silver;
}</pre>

<h2 id="Syntaxe">Syntaxe</h2>

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

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

<h3 id="Exemple_simple">Exemple simple</h3>

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

<div class="hidden">
<pre class="brush: css">input:-ms-input-placeholder {
  border-color: silver;
}

input:-moz-placeholder {
  border-color: silver;
}</pre>
</div>

<pre class="brush: css; highlight[6]">input {
  border: 2px solid black;
  padding: 3px;
}

:placeholder-shown {
  border-color: silver;
}</pre>

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

<pre class="brush: html">&lt;input placeholder="Saisir quelque chose ici"&gt;</pre>

<h4 id="Résultat">Résultat</h4>

<p>{{EmbedLiveSample("Exemples", 200, 60)}}</p>

<h3 id="Dépassement_du_texte">Dépassement du texte</h3>

<p>Sur certains écrans plus étroits (tels que ceux des smartphones), la largeur des boîtes de recherche et celle des champs de formulaire peut être réduite fortement. Le texte de substitution peut donc être tronqué de façon indésirable. On peut alors utiliser {{cssxref("text-overflow")}} pour gérer cela gracieusement.</p>

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

<pre class="brush: html">&lt;input placeholder="Veuillez saisir quelque chose dans ce champ s'il vous plaît !"&gt;</pre>

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

<div class="hidden">
<pre class="brush: css">input:-ms-input-placeholder {
  text-overflow: ellipsis;
}

input:-moz-placeholder {
  text-overflow: ellipsis;
}</pre>
</div>

<pre class="brush: css">input:placeholder-shown {
  text-overflow: ellipsis;
}</pre>

<h4 id="Résultat_2">Résultat</h4>

<p>{{EmbedLiveSample("Dépassement_du_texte", 200, 60)}}</p>

<h3 id="Texte_coloré">Texte coloré</h3>

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

<pre class="brush: html">&lt;input placeholder="Saisir quelque chose ici"&gt;</pre>

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

<div class="hidden">
<pre class="brush: css">input:-ms-input-placeholder {
  color: red;
  font-style: italic;
}

input:-moz-placeholder {
  color: red;
  font-style: italic;
}</pre>
</div>

<pre class="brush: css">input:placeholder-shown {
  color: red;
  font-style: italic;
}
</pre>

<h4 id="Résultat_3">Résultat</h4>

<p>{{EmbedLiveSample("Texte_coloré")}}</p>

<h3 id="Champ_de_saisie_personnalisé">Champ de saisie personnalisé</h3>

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

<pre class="brush: html">&lt;form id="test"&gt;
  &lt;p&gt;
    &lt;label for="name"&gt;Enter Student Name:&lt;/label&gt;
    &lt;input id="name" placeholder="Student Name"/&gt;
  &lt;/p&gt;
  &lt;p&gt;
    &lt;label for="branch"&gt;Enter Student Branch:&lt;/label&gt;
    &lt;input id="branch" placeholder="Student Branch"/&gt;
  &lt;/p&gt;
  &lt;p&gt;
    &lt;label for="sid"&gt;Enter Student ID:&lt;/label&gt;
    &lt;input type="number" pattern="[0-9]{8}" title="8 digit ID" id="sid" class="studentid" placeholder="8 digit id"/&gt;
  &lt;/p&gt;
  &lt;input type="submit"/&gt;
&lt;/form&gt;</pre>

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

<div class="hidden">
<pre class="brush: css">input.studentid:-ms-input-placeholder {
  background-color: yellow;
  color: red;
  font-style: italic;
}

input.studentid:-moz-placeholder {
  background-color: yellow;
  color: red;
  font-style: italic;
}</pre>
</div>

<pre class="brush: css; highlight[6]">input {
  background-color: #E8E8E8;
  color: black;
}

input.studentid:placeholder-shown {
  background-color: yellow;
  color: red;
  font-style: italic;
}</pre>

<h4 id="Résultat_4">Résultat</h4>

<p>{{EmbedLiveSample("Champ_de_saisie_personnalisé", 200, 180)}}</p>

<h2 id="Spécifications">Spécifications</h2>

<table class="standard-table">
 <thead>
  <tr>
   <th scope="col">Spécification</th>
   <th scope="col">État</th>
   <th scope="col">Commentaires</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td>{{SpecName("CSS4 Selectors", "#placeholder", ":placeholder-shown")}}</td>
   <td>{{Spec2("CSS4 Selectors")}}</td>
   <td>Définition initiale.</td>
  </tr>
 </tbody>
</table>

<h2 id="Compatibilité_des_navigateurs">Compatibilité des navigateurs</h2>

<p class="hidden">Pour contribuer à ces données de compatibilité, vous pouvez envoyer une <em>pull request</em> sur ce dépôt: <a href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a>.</p>

<p>{{Compat("css.selectors.placeholder-shown")}}</p>

<h2 id="Voir_aussi">Voir aussi</h2>

<ul>
 <li>{{cssxref("::placeholder")}}</li>
 <li>{{cssxref("::-moz-placeholder")}}</li>
 <li>{{HTMLElement("input")}}</li>
 <li>{{HTMLElement("textarea")}}</li>
 <li><a href="/fr/docs/Web/Guide/HTML/Formulaires">Les formulaires HTML</a></li>
</ul>