<form id="form">
<span class="input input--hoshi">
<input class="input__field input__field--hoshi" type="text" id="input-4" name="field1" />
<label class="input__label input__label--hoshi input__label--hoshi-color-1" for="input-4">
<span class="input__label-content input__label-content--hoshi">Name <span class="error"></span></span>
</label>
</span>
</form>
.error {
color: red;
}
.input {
position: relative;
z-index: 1;
display: inline-block;
margin: 80px 0 0 100px;
}
.input__field {
position: relative;
display: block;
padding: 0.8em;
border: none !important;
border-radius: 0;
background: #f0f0f0;
color: #aaa;
font-size: 18px;
appearance: none; /* for box shadows to show on iOS */
}
.input__field:focus {
outline: none;
}
.input__label {
display: inline-block;
width: 40%;
color: #6a7989;
font-weight: bold;
font-size: 70.25%;
touch-callout: none;
user-select: none;
user-select: none;
user-select: none;
user-select: none;
user-select: none;
}
.input__label-content {
position: relative;
display: block;
padding: 1.6em 0;
width: 100%;
font-family: 'Open Sans', sans-serif;
}
/* Hoshi */
.input--hoshi {
overflow: hidden;
}
.input__field--hoshi {
margin-top: 0.85em;
padding: 0.85em 0.15em;
width: 100%;
background: transparent;
color: #595F6E;
}
.input__label--hoshi {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
text-align: left;
pointer-events: none;
}
.input__label-content--hoshi {
position: absolute;
}
.input__label--hoshi::before,
.input__label--hoshi::after {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: calc(100% - 10px);
border-bottom: 1px solid #B9C1CA;
}
.input__label--hoshi::after {
border-bottom: 4px solid red;
transform: translate3d(-100%, 0, 0);
transform: translate3d(-100%, 0, 0);
transition: transform 0.3s;
transition: transform 0.3s;
}
.input__label--hoshi-color-1::after {
border-color: hsl(200, 100%, 50%);
}
.input__field--hoshi:focus + .input__label--hoshi::after,
.input--filled + .input__label--hoshi::after {
transform: translate3d(0, 0, 0);
transform: translate3d(0, 0, 0);
}
.input__field--hoshi:focus + .input__label--hoshi .input__label-content--hoshi,
.input--filled + .input__label--hoshi .input__label-content--hoshi {
animation: anim-1 0.3s forwards;
animation: anim-1 0.3s forwards;
}
@-webkit-keyframes anim-1 {
50% {
opacity: 0;
transform: translate3d(1em, 0, 0);
transform: translate3d(1em, 0, 0);
}
51% {
opacity: 0;
transform: translate3d(-1em, -40%, 0);
transform: translate3d(-1em, -40%, 0);
}
100% {
opacity: 1;
transform: translate3d(0, -40%, 0);
transform: translate3d(0, -40%, 0);
}
}
View Compiled
$(document).ready(function(){
$('#form').validate({
onkeyup: false,
rules: {
field1: {
required: true,
minlength: 5
}
},
errorLabelContainer: '.error',
submitHandler: function(form) {
alert('valid form');
return false;
}
});
$('.input__field').change(function() {
var $this = $(this);
var $thisInput = $this.find('input');
if ($this.val() !== "") {
$this.addClass('input--filled');
} else {
$this.removeClass('input--filled');
}
});
$('.input__field').blur(function(){
});
});
This Pen doesn't use any external CSS resources.