Is it possible to keep my label positioned on top of the input field even after filling in data?
I attempted using the valid function in CSS, but did not achieve the desired functionality.
.txt_field input {
width: 100%;
padding: 0 5px;
height: 40px;
font-size: 16px;
border: none;
background: none;
outline: none;
}
.txt_field label {
position: absolute;
top: 65%;
left: 5px;
color: #adadad;
transform: translateY(-50%);
font-size: 16px;
pointer-events: none;
transition: .3s;
}
.txt_field input:focus~label {
top: 0px;
color: #0170C1;
}
<div class="txt_field">
<i class="fa fa-user"></i>
<input type="text" class="textbox" id="username" placeholder="">
<label>PhoneNumber/Email</label>
</div>
I have tried .txt_field input:focus ~valid
, but unfortunately the label keeps overlapping with the input data.
Seeking advice on how to ensure the label remains on top once the input field is filled.