Skip to content

Instantly share code, notes, and snippets.

@AllThingsSmitty
Created June 26, 2015 00:07
Show Gist options
  • Save AllThingsSmitty/2a9361409f42bff00608 to your computer and use it in GitHub Desktop.
Save AllThingsSmitty/2a9361409f42bff00608 to your computer and use it in GitHub Desktop.
Using Level 4 CSS validity pseudo-classes to improve form UX
<div class="container">
<form class="form">
<div class="form-group">
<label class="sr-only" for="emailAddress">Email Address</label>
<input class="form-control input-lg" type="email" placeholder="example@email.com" id="emailAddress" required>
<button type="submit" class="btn btn-default input-lg">Subscribe</button>
</form>
</div>
.container {
display: flex;
margin: 50px auto 0;
max-width: 500px;
}
form {
display: block;
width: 100%;
}
button {
display: block;
margin-top: 10px;
width: 100%;
}
input[ type=email ] {
border-width: 5px;
&:focus {
// target the element when it isn't valid
&:invalid {
border-color: #a94442;
box-shadow: inset 0 1px 1px rgba(0,0,0,.075);
color: #a94442;
}
// target the element once a valid
// email address has been entered
&:valid {
border-color: #3c763d;
box-shadow: inset 0 1px 1px rgba(0,0,0,.075);
color: #3c763d;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment