I am trying to achieve a floating placeholder functionality. Everything works fine with the code I have written except for the fact that when there is an email field and I try to add a wrong entry which is not of an email format and i shift focus from the input box, the floating text still appears. You can check the codepen link
Belew is my code:-
.-input-container {
max-width: 540px;
padding-bottom: 30px;
margin-top: 30px;
}
input.-textbox {
width: 100%;
border-radius: 40px;
background-color: #f5f5f5;
border: 1px solid #dddddd;
padding: 16px 30px;
font-size: 16px;
color: #555555;
font-family: OpenSans;
font-weight: normal;
font-style: normal;
font-stretch: normal;
line-height: 1.88;
letter-spacing: normal;
text-align: left;
}
input.-textbox:focus{
outline: none;
box-shadow: none
}
input.-textbox:focus ~ .floating-label,
input.-textbox:not(:focus):valid ~ .floating-label {
top: 8px;
bottom: 10px;
left: 45px;
font-size: 10px;
opacity: 1;
line-height: 2.1;
font-family: OpenSans;
}
input.-textbox ~ .floating-label {
position: absolute;
pointer-events: none;
left: 45px;
top: 18px;
transition: 0.2s ease all;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.0/css/bootstrap.css" rel="stylesheet"/>
<div class="-input-container col-xl-6 col-lg-6 col-md-12 col-sm-12 col-12 ">
<input type="email" class="-textbox form-control" required="">
<span class="floating-label">E-postadress</span>
</div>
3
Answers
Try this:
Use javascript in it. Try this
It is simple with some Javascript and minor changes in styles. Try this one.