Skip to content

Instantly share code, notes, and snippets.

@CantonBolo
Last active August 29, 2015 13:58
Show Gist options
  • Save CantonBolo/10353336 to your computer and use it in GitHub Desktop.
Save CantonBolo/10353336 to your computer and use it in GitHub Desktop.
A Pen by CantonBolo.
<form>
<div class='input'>
<input type="text" id='name' />
<label for='name'>Your Name</label>
</div>
<div class='input'>
<input type="text" id='address' />
<label for='address'>Address</label>
</div>
</form>
var inputs = document.getElementsByTagName('input');
for( i=0 ; i<inputs.length; i++ ) {
var input = inputs[i];
input.addEventListener('keyup',bindUI, false);
}
function bindUI() {
if( this.value ) {
this.classList.add('not-empty');
} else {
this.classList.remove('not-empty');
}
}
@import "compass";
form{
margin:5em;
backface-visibility:hidden;
}
.input{
position:relative;
float:left;
margin:10px;
}
input{
border:1px solid #eee;
padding:1em .5em;
outline:none;
}
input + label
{
position:absolute;
left:10px;
top:50%;
transform:translateY(-50%);
color:#aaa;
transition:all .2s ease;
}
input:focus + label,
.not-empty + label{
color:#52A5FB;
font-size:.65em;
top:8%;
transform:none;
}
.not-empty + label{
color:#aaa;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment