aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/css/_colon_valid/index.html
blob: 14eac092a6f01c8f2cf7be838a3f668692162971 (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
---
title: ':valid'
slug: 'Web/CSS/:valid'
tags:
  - CSS
  - Layout
  - Pesudo-class
  - Reference
  - Web
translation_of: 'Web/CSS/:valid'
---
<div>{{ CSSRef() }}</div>

<p><code>:valid</code> CSS <a href="/en/CSS/Pseudo-classes" title="Pseudo-classes">伪类</a>表示内容<a href="/en/HTML/HTML5/Constraint_validation" title="en/HTML/HTML5/Constraint_validation">验证</a>正确的{{ HTMLElement("input") }} 或其他 {{ HTMLElement("form") }} 元素。这能简单地将校验字段展示为一种能让用户辨别出其输入数据的正确性的样式。</p>

<pre class="brush: css no-line-numbers">/* Selects any valid &lt;input&gt; */
input:valid {
  background-color: powderblue;
}</pre>

<p>该伪类对于高亮正确字段是很有用的。</p>

<h2 id="语法">语法</h2>

{{csssyntax}}

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

<p>参见 {{cssxref(":invalid")}}</p>

<p> </p>

<h2 id="Accessibility_concerns">Accessibility concerns</h2>

<p>绿色常用于表示有效输入。但某些色盲的人将无法确定输入的状态(颜色),除非使用不依赖于颜色来传达意义的附加指示器。 通常,指示器使用描述性文本和(或)图标。</p>

<ul>
 <li><a href="https://developer.mozilla.org/en-US/docs/Web/Accessibility/Understanding_WCAG/Perceivable#Guideline_1.4_Make_it_easier_for_users_to_see_and_hear_content_including_separating_foreground_from_background">MDN Understanding WCAG, Guideline 1.4 explanations</a></li>
 <li><a href="https://www.w3.org/TR/UNDERSTANDING-WCAG20/visual-audio-contrast-without-color.html">Understanding Success Criterion 1.4.1  | W3C Understanding WCAG 2.0</a></li>
</ul>

<h2 id="规范">规范</h2>

<table class="standard-table" style="color: #3b3c40; font-size: 14px; font-weight: normal;">
 <thead>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td>{{ SpecName('HTML WHATWG', '#selector-valid', ':valid') }}</td>
   <td>{{ Spec2('HTML WHATWG') }}</td>
   <td>No change.</td>
  </tr>
  <tr>
   <td>{{ SpecName('HTML5 W3C', '#selector-valid', ':valid') }}</td>
   <td>{{ Spec2('HTML5 W3C') }}</td>
   <td>Defines the semantic regarding HTML and constraint validation.</td>
  </tr>
  <tr>
   <td>{{ SpecName('CSS4 Selectors', '#validity-pseudos', ':valid') }}</td>
   <td>{{ Spec2('CSS4 Selectors') }}</td>
   <td>Initial definition.</td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility">Browser compatibility</h2>

<div>


<p>{{Compat("css.selectors.valid")}}</p>
</div>

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

<ul>
 <li>{{ cssxref(":invalid") }}, {{ cssxref(":required") }}, {{ cssxref(":optional") }}</li>
 <li><a href="https://developer.mozilla.org/en-US/docs/Learn/HTML/Forms/Form_validation">Form data validation</a></li>
</ul>