Skip to content

Instantly share code, notes, and snippets.

@niktariy
Last active July 10, 2019 11:54
Show Gist options
  • Save niktariy/93ac71a9eff030a78b522dedfa5f80d4 to your computer and use it in GitHub Desktop.
Save niktariy/93ac71a9eff030a78b522dedfa5f80d4 to your computer and use it in GitHub Desktop.
Reqiured / Valid / Invalid fields CSS styling
/* 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;
}
<!-- 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