Material Input with floating Label
Signup form with floating label inspired by google's material design.
by Marie Gérard
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0-alpha1/jquery.min.js"></script>
<div class="wrapper">
<form>
<div class="input-box">
<input type="text" name="fname" value="">
<label for="fname">Full Name</label>
</div>
<div class="input-box">
<input type="email" name="email" value="">
<label for="email">Email</label>
</div>
<div class="input-box">
<input type="password" name="pass" value="">
<label for="pass">Password</label>
</div>
<div class="input-box">
<input type="password" name="cpass" value="">
<label for="cpass">Confirm Password</label>
</div>
<input type="submit" value="SIGN UP">
</form>
</div>
CSS
*{
box-sizing: border-box;
}
body{
font-family: sans-serif;
}
.wrapper {
width: 460px;
margin: 0 auto;
box-shadow: 0 0 15px RGBA(0, 0, 0, 0.24);
border-radius: 5px;
padding: 20px 25px;
text-align: center;
margin-top: 60px;
}
.input-box {
position: relative;
margin-bottom: 20px;
}
input{
background: none;
padding: 15px 40px;
font-size: 18px;
color: #0db5c2;
width: 100%;
}
input:active,
input:focus{
outline: none;
}
input[type=text],
input[type=email],
input[type=password]{
padding: 15px 0;
border: none;
border-bottom: 2px solid #51f3ff;
}
input[type=submit]{
background-color: #0db5c2;
color: #fff;
border-radius: 5px;
border-style: none;
cursor: pointer;
margin-top: 20px;
-webkit-transition: all .3s ease-in-out;
transition: all .3s ease-in-out;
}
input[type=submit]:hover{
background-color: #fff;
color: #0db5c2;
text-shadow: 0 0 5px RGBA(0, 0, 0, 0.27);
box-shadow: 0 0 5px RGBA(0, 0, 0, 0.27);
}
label {
position: absolute;
left: 0;
top: 35%;
color: #999;
font-style: italic;
font-size: 15px;
pointer-events: none;
-webkit-transition: all .2s ease-in-out;
transition: all .2s ease-in-out;
}
input[type=text]:focus + label,
input[type=email]:focus + label,
input[type=password]:focus + label,
.float-label + label{
top: -8px;
color: #0db5c2;
font-size: 13px;
}
JavaScript
$(document).ready(function(){
$('.wrapper input').focusout(function(){
var text_value = $(this).val();
if (text_value === "") {
$(this).removeClass('float-label');
}else {
$(this).addClass('float-label');
}
});
});