I want the span in my label to move up when my input is on focus and valid mode, on email type input, when i write anything but an email format text, and then focus out of the input, the span comes back down, I just want it to stay up even if the format of my text is not "email".
.form-group {
position: relative;
}
.form-group input {
width: 100%;
height: 100%;
color: #595f6e;
padding-top: 20px;
border: none;
outline: none;
}
.form-group label {
height: 100%;
position: absolute;
left: 0;
bottom: 0;
pointer-events: none;
width: 100%;
border-bottom: 1px solid black;
margin: 0 !important;
}
.form-group label::after {
content: "";
position: absolute;
left: 0px;
bottom: -1px;
height: 100%;
width: 100%;
border-bottom: 3px solid #5fa8d3;
transform: translateX(-100%);
}
.form-group label .content-name {
position: absolute;
bottom: 5px;
left: 0px;
transition: all 0.3s ease;
}
.form-group input:focus + .label-name .content-name,
.form-group input:valid + .label-name .content-name {
transform: translateY(-80%);
font-size: 14px;
color: #5fa8d3;
}
<form id="loginForm" action="{{ url_for('login.login') }}" method="POST">
<div class="form-group">
<input type="email" id="email" name="email"
pattern="[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}" required>
<label class="label-name">
<span class="content-name">
Name
</span>
</label>
</div>
</form>
input[value=""]only works if the input's value was set to exactly that before loading the page, and it doesn't respond to changes in the input's value. You'd have to use some sort of JavaScript to set something along the lines of an "is-dirty" class and use that in your CSS. That's pretty much what frameworks like Knockout.js do (no idea about Angular, React, etc.).