'Prevent label text from overlapping input text
I created an input field, but when a user clicks off the user input, the span text overlays the input text. How can I prevent this from happening? I feel like I have tried everything!
.label {
display: inline-block;
margin: 10px;
}
.form-input {
margin: 10px;
}
.label span {
z-index: 1;
position: absolute;
cursor: text;
pointer-events: none;
color: #999;
padding-left: 10px;
line-height: 54px;
font-family: Arial, Helvetica, sans-serif;
transition: all ease-out 0.1s;
}
.label:focus-within>span {
/* Move span text up on focus */
line-height: 26px;
font-size: 12px;
transition: ease-in-out 0.2s;
color: rgb(29, 161, 242);
}
.label input {
z-index: 0;
width: 258px;
height: 22px;
padding-bottom: 14px;
padding-top: 14px;
padding-left: 9px;
font-size: 16px;
font-family: Arial, Helvetica, sans-serif
}
.label input:focus {
padding-top: 20px;
padding-bottom: 8px;
transition: all ease-in-out 0.1s;
}
<div>
<form class='form-input'>
<label class='label'>
<span class='span-text'>Email</span>
<input value=''></input>
</label>
</form>
</div>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
