Last active
July 10, 2019 11:54
-
-
Save niktariy/93ac71a9eff030a78b522dedfa5f80d4 to your computer and use it in GitHub Desktop.
Reqiured / Valid / Invalid fields CSS styling
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 */ | |
.msg-validation { display: block; } | |
.input-field:required ~ .msg-validation::before { | |
content: '*Обязательное'; | |
} | |
.input-field:invalid:not(:placeholder-shown) { | |
border-color: red; | |
background-color: rgba(red, 0.1); | |
} | |
.input-field:invalid:not(:placeholder-shown) ~ .msg-validation::before { | |
content: 'Заполните это поле'; | |
color: red; | |
} | |
.input-field:valid { | |
border-color: lightgreen; | |
background-color: rgba(lightgreen, 0.1); | |
} | |
.input-field:valid ~ .msg-validation::before { | |
display: none; | |
} |
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 for="required" class="input-label">Обязательное поле</label> | |
<input class="input-field" type="email" id="required" | |
placeholder="E-mail" required> | |
<span class="msg-validation"></span> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment