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
|
---
title: ':out-of-range'
slug: 'Web/CSS/:out-of-range'
translation_of: 'Web/CSS/:out-of-range'
---
<div>{{CSSRef}}</div>
<div><strong><code>:out-of-range</code> </strong><a href="https://developer.mozilla.org/en-US/docs/Web/CSS">CSS</a> <a href="https://developer.mozilla.org/en-US/docs/CSS/Pseudo-classes">伪类</a> 表示一个 {{htmlelement("input")}} 元素,其当前值处于属性 <code><a href="https://developer.mozilla.org/zh-CN/docs/Web/HTML/Element/input#attr-min">min</a></code> 和 <code><a href="https://developer.mozilla.org/zh-CN/docs/Web/HTML/Element/input#attr-max">max</a></code> 限定的范围外。</div>
<div> </div>
<pre class="brush: css">/* 该伪类可选定任意的<input>, 但只有在该元素指定了取值范围,并且元素值处于指定范围时才有效 */
input:out-of-range {
background-color: rgba(255, 0, 0, 0.25);
}</pre>
<p>该伪类用于给用户一个可视化的提示,表示输入域的当前值处于允许范围外。</p>
<div class="note">注意:该伪类仅适用于那些拥有(或可以接受)取值范围设定的元素。若缺少此类设定,元素值就无所谓“in-range”和“out-range”。</div>
<h2 id="语法">语法</h2>
<pre class="syntaxbox">{{csssyntax}}</pre>
<h2 id="Example" name="Example">示例</h2>
<div id="example">
<h3 id="HTML">HTML</h3>
<pre class="brush: html"><form action="" id="form1">
<ul>Values between 1 and 10 are valid.
<li>
<input id="value1" name="value1" type="number" placeholder="1 to 10" min="1" max="10" value="12">
<label for="value1">Your value is </label>
</li>
</ul>
</form></pre>
<h3 id="CSS">CSS</h3>
<pre class="brush: css;">li {
list-style: none;
margin-bottom: 1em;
}
input {
border: 1px solid black;
}
input:in-range {
background-color: rgba(0, 255, 0, 0.25);
}
input:out-of-range {
background-color: rgba(255, 0, 0, 0.25);
border: 2px solid red;
}
input:in-range + label::after {
content: 'okay.';
}
input:out-of-range + label::after {
content: 'out of range!';
}</pre>
<h3 id="输出">输出</h3>
</div>
<div>{{EmbedLiveSample('Example', 600, 140)}}</div>
<h2 id="规范"><span>规范</span></h2>
<table class="standard-table">
<thead>
<tr>
<th scope="col">规范</th>
<th scope="col">状态</th>
<th scope="col">备注</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{SpecName('HTML WHATWG', 'scripting.html#selector-out-of-range', ':out-of-range')}}</td>
<td>{{Spec2('HTML WHATWG')}}</td>
<td>Defines when <code>:out-of-range</code> matches elements in HTML.</td>
</tr>
<tr>
<td>{{SpecName('CSS4 Selectors', '#out-of-range-pseudo', ':out-of-range')}}</td>
<td>{{Spec2('CSS4 Selectors')}}</td>
<td>Initial definition.</td>
</tr>
</tbody>
</table>
<h2 id="浏览器兼容性">浏览器兼容性</h2>
<div>
<div>
<p>{{Compat("css.selectors.out-of-range")}}</p>
</div>
</div>
<h2 id="参阅">参阅</h2>
<ul>
<li>{{cssxref(":in-range")}}</li>
<li><a href="/en-US/docs/Learn/HTML/Forms/Form_validation">Form data validation</a></li>
</ul>
|