Last active
July 10, 2019 11:55
-
-
Save niktariy/d9980599c051a06a776a0ca7f19f9b5e to your computer and use it in GitHub Desktop.
Input number with in- / out-of-range validation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* CSS */ | |
.input-field:valid { | |
border-color: lightgreen; | |
background-color: rgba(lightgreen, 0.1); | |
} | |
.input-field:valid ~ .msg-validation::before { | |
display: none; | |
} | |
.input-field:invalid { | |
border-color: red; | |
background-color: rgba(red, 0.1); | |
} | |
.input-field:out-of-range + .msg-validation::before { | |
content: 'Неверное значение'; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- HTML --> | |
<div class="form-group"> | |
<label class="input-label" for="in-range">In-range input</label> | |
<input class="input-field" type="number" id="in-range" | |
min="1" max="10" value="8" required> | |
<span class="msg-validation range"> ( введите значение между 1 и 10 )</span> | |
</div> | |
<div class="form-group"> | |
<label class="input-label" for="out-of-range">Out-of-range input</label> | |
<input class="input-field" type="number" id="out-of-range" | |
min="1" max="10" value="12" required> | |
<span class="msg-validation range"> ( введите значение между 1 и 10 )</span> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment