Utilizing an angularjs form, I have customized the following example to fit 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 issue arises when an invalid input is provided, causing the placeholder to revert to its initial state and position itself on the invalid input. Therefore, the objective is to maintain the floating placeholder even in the case of invalid email inputs. How can the floating placeholder be retained for invalid email inputs as well?
If I incorporate:
.form-control:invalid + .form-control-placeholder
into the current floating CSS, it will remain floating when no input is provided. The goal is to prevent it from floating when empty.