aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/css/_colon_placeholder-shown/index.html
blob: 86fd5a91c95bab94cc1c810c8afed3657d02225a (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
---
title: ':placeholder-shown'
slug: 'Web/CSS/:placeholder-shown'
translation_of: 'Web/CSS/:placeholder-shown'
---
<div>{{CSSRef}}{{SeeCompatTable}}</div>

<p><strong><code>:placeholder-shown</code></strong> <a href="/en-US/docs/Web/CSS">CSS</a> <a href="/zh-CN/docs/CSS/Pseudo-classes">伪类</a> 在 {{htmlElement("input")}}{{htmlElement("textarea")}} 元素显示 <a href="/en-US/docs/Web/HTML/Element/input#attr-placeholder">placeholder text</a> 时生效.</p>

<pre class="brush: css no-line-numbers">/* 选择所有显示占位符(placeholder)的元素 */
:placeholder-shown {
  border: 2px solid silver;
}</pre>

<h2 id="参数">参数</h2>

<pre class="syntaxbox">:placeholder-shown</pre>

<h2 id="样例">样例</h2>

<h3 id="基础样例">基础样例</h3>

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

<pre class="brush: html">&lt;input placeholder="Type something here!"&gt;</pre>

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

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

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

<h4 id="结果">结果</h4>

<p>{{EmbedLiveSample('Basic_example', 200, 60)}}</p>

<h3 id="超出文本">超出文本</h3>

<p>在分辨率较小的设备上, 输入框或者其他表单控件可能会变的很窄. 这个选择器可以使得占位符文本缩短. 这个选择器经常和 {{cssxref("text-overflow")}} 一起使用.</p>

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

<pre class="brush: html">&lt;input placeholder="Enter something into this field, if you please!"&gt;</pre>

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

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

<h4 id="结果_2">结果</h4>

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

<h2 id="规范">规范</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>{{SpecName("CSS4 Selectors", "#placeholder", ":placeholder-shown")}}</td>
   <td>{{Spec2("CSS4 Selectors")}}</td>
   <td>Initial definition.</td>
  </tr>
 </tbody>
</table>

<h2 id="浏览器兼容性">浏览器兼容性</h2>



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

<h2 id="参见">参见</h2>

<ul>
 <li>The {{cssxref("::placeholder")}} pseudo-element styles the placeholder <em>itself</em>.</li>
 <li>Related HTML elements: {{HTMLElement("input")}}, {{HTMLElement("textarea")}}</li>
 <li>{{cssxref(":-moz-placeholder")}}, {{cssxref("::-moz-placeholder")}}</li>
 <li><a href="/en-US/docs/Learn/HTML/Forms">HTML forms</a></li>
</ul>