I am using angularjs form, and I have the following example adapted to my code:
.my-5 {
margin:100px;
}
.form-group {
position: relative;
margin-bottom: 1.5rem;
}
.form-control-placeholder {
position: absolute;
top: 0;
padding: 7px 0 0 13px;
transition: all 200ms;
opacity: 0.5;
}
.form-control:focus + .form-control-placeholder,
.form-control:valid + .form-control-placeholder {
font-size: 75%;
transform: translate3d(0, -100%, 0);
opacity: 1;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container my-5">
<div class="row">
<div class="col-md-6 mx-auto">
<div class="form-group">
<input type="email" id="email" class="form-control" required>
<label class="form-control-placeholder" for="email">email</label>
</div>
</div>
</div>
</div>
the problem is that when an invalid input is given, the placeholder returns to the initial state and gets positioned on the invalid input. So the idea is to apply the floating placeholder in case of invalid inputs as well. How can I maintain the floating placeholder in case of invalid email input as well?
if I add :
.form-control:invalid + .form-control-placeholder
to the current floating css, it will always be floating when no input is given. So the idea is to not float when it is empty.