Skip to content

Instantly share code, notes, and snippets.

@divins
Last active December 25, 2015 10:19
Show Gist options
  • Save divins/6960679 to your computer and use it in GitHub Desktop.
Save divins/6960679 to your computer and use it in GitHub Desktop.
<div class="input">
<input id="foo" placeholder="Foo">
<label for="foo">Foo</label>
</div>
<div class="input">
<input id="bar" placeholder="Bar">
<label for="bar">Bar</label>
</div>
<script type="text/javascript">$(function() {
$('input').keyup(function(){
label = $('label[for="'+this.id+'"]')
if( !this.value ) {
label.removeClass('filled')
}
else{
label.addClass('filled')
}
})
});</script>
.input {
position: relative;
}
.input label {
opacity: 0;
position: absolute;
top: 0px;
left: 0px;
font-size: 11px;
}
.input label.filled {
opacity: 1;
-webkit-transition-property: opacity;
-moz-transition-property: opacity;
-o-transition-property: opacity;
transition-property: opacity;
-webkit-transition-duration: 0.3s;
-moz-transition-duration: 0.3s;
-o-transition-duration: 0.3s;
transition-duration: 0.3s;
top: -3px;
-webkit-transition-property: top;
-moz-transition-property: top;
-o-transition-property: top;
transition-property: top;
}
.input input {
border: 0;
border-bottom: 1px solid #bbbbbb;
outline: none;
margin: 10px 0px;
font-size: 15px;
}
.input input:focus + label {
color: blue;
}
.input
position: relative
label
opacity: 0
position: absolute
top: 0px
left: 0px
font-size: 11px
&.filled
opacity: 1
+transition-property(opacity)
+transition-duration(0.3s)
top: -3px
+transition-property(top)
input
border: 0
bottom: 1px solid #bbb
outline: none
margin: 10px 0px
font-size: 15px
&:focus + label
color: blue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment