:out-of-range
åºçº¿
广æ³å¯ç¨
èª 2015å¹´11æ èµ·ï¼æ¤ç¹æ§å·²å¨ä¸»æµæµè§å¨ä¸å¾å°æ¯æï¼å¯å¨å¤§å¤æ°è®¾å¤åæµè§å¨çæ¬ä¸æ£å¸¸ä½¿ç¨ã
:out-of-range CSS 伪类表示ä¸ä¸ª <input> å
ç´ ï¼å
¶å½åå¼å¤äºå±æ§ min å max éå®çèå´å¤ã
å°è¯ä¸ä¸
label {
display: block;
margin-top: 1em;
}
input:out-of-range {
background-color: orangered;
}
<form>
<label for="amount">How many tickets? (You can buy 2-6 tickets)</label>
<input id="amount" name="amount" type="number" min="2" max="6" value="4" />
<label for="dep">Departure Date: (Whole year 2022 is acceptable)</label>
<input
id="dep"
name="dep"
type="date"
min="2022-01-01"
max="2022-12-31"
value="2025-05-05" />
<label for="ret">Return Date: (Whole year 2022 is acceptable)</label>
<input id="ret" name="ret" type="date" min="2022-01-01" max="2022-12-31" />
</form>
è¿ä¸ªä¼ªç±»å¾æç¨ï¼å¯ä»¥ç»ç¨æ·æä¾ä¸ä¸ªè§è§æç¤ºï¼è®©ä»ä»¬ç¥éåæ®µçå½å弿¯å¦è¶ åºäºå 许çèå´ã
夿³¨ï¼è¯¥ä¼ªç±»ä» éç¨äºå ·æï¼å¹¶å¯ä»¥æ¥åï¼èå´éå¶çå ç´ ãå¦ææ²¡æè¿æ ·çéå¶ï¼å ç´ å¼å°±æ æè°âin-rangeâåâout-of-rangeâã
è¯æ³
css
:out-of-range {
/* ... */
}
示ä¾
>HTML
html
<form action="" id="form1">
<p>Values between 1 and 10 are valid.</p>
<ul>
<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>
CSS
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!";
}
ç»æ
è§è
| è§è |
|---|
| HTML> # selector-out-of-range> |
| Selectors Level 4> # out-of-range-pseudo> |