Skip to content

Instantly share code, notes, and snippets.

@patw0929
Last active July 26, 2016 03:24
Show Gist options
  • Save patw0929/884e2efcfa2bab51573d98011df159a9 to your computer and use it in GitHub Desktop.
Save patw0929/884e2efcfa2bab51573d98011df159a9 to your computer and use it in GitHub Desktop.
Pure CSS text input with required tip
<div class="wrapper">
<input type="text" required>
<span class="tip">Required!</span>
</div>
input:invalid {
outline: 1px solid red;
}
.tip {
display: none;
}
input:invalid + .tip {
display: inline-block;
color: #fff;
background-color: #f00;
margin-left: 10px;
padding: 2px;
position: relative;
}
.tip:after {
position: absolute;
left: -10px;
top: 0;
bottom: 0;
margin: auto;
content: '';
width: 0;
height: 0;
border-top: 5px solid transparent;
border-bottom: 5px solid transparent;
border-right: 10px solid red;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment