Why is floating label not working with css - html

I am try to recreate the floating labels from this tutorial.
when I add this code from the tutorial (check 15:00 in the tutorial)
.form-group input:focus + .label-name .content-name,
.form-group input:valid + .label-name .content-name {
transform: translateY(-120%);
font-size: 14px;
color: #5fa8d3;
}
The label loses the floating effect. Check the image below. This state of the label should only be active when the input is focused. But for some weird reason this is the default state. This only happens when add .form-group input:valid + .label-name .content-name to the code above.
Here is my full code
.form-group {
position: relative;
width: 100%;
height: 100%;
overflow: hidden;
}
.form-group input {
width: 100%;
height: 100%;
color: #595f6e;
background-color: #fbf9fa;
padding-top: 20px;
border: none;
}
.form-group input:focus {
background-color: #fbf9fa;
}
.form-group label {
position: absolute;
bottom: -10px;
left: 0%;
width: 100%;
height: 120%;
pointer-events: none;
border-bottom: 1px solid black;
}
.form-group label::after {
content: "";
position: absolute;
left: 0px;
bottom: -1px;
height: 100%;
width: 100%;
border-bottom: 3px solid #5fa8d3;
transform: translateX(-100%);
transition: transform 0.5s ease;
}
.content-name {
position: absolute;
bottom: 5px;
left: 0px;
transition: all 0.5s ease;
}
.form-group input:focus + .label-name .content-name,
.form-group input:valid + .label-name .content-name {
transform: translateY(-120%);
font-size: 14px;
color: #5fa8d3;
}
html
<div class="form-group">
<input type="text" class="form-control" name='input-name'>
<label for="input-name" class='label-name'>
<span class='content-name'>Enter your name</span>
</label>
</div>

I don't have all your css, but with the snippet you gave I was able to get it working by adding the required attribute to the input.
When you don't have the required attribute, the input is always "valid". Therefore, the css selector that had :valid was always being applied.
See demo in the snippet below:
.form-group {
position: relative;
width: 100%;
height: 100%;
overflow: hidden;
}
.form-group input {
width: 100%;
height: 100%;
color: #595f6e;
background-color: #fbf9fa;
padding-top: 20px;
border: none;
}
.form-group input:focus {
background-color: #fbf9fa;
}
.form-group label {
position: absolute;
bottom: -10px;
left: 0%;
width: 100%;
height: 120%;
pointer-events: none;
border-bottom: 1px solid black;
}
.form-group label::after {
content: "";
position: absolute;
left: 0px;
bottom: -1px;
height: 100%;
width: 100%;
border-bottom: 3px solid #5fa8d3;
transform: translateX(-100%);
transition: transform 0.5s ease;
}
.content-name {
position: absolute;
bottom: 5px;
left: 0px;
transition: all 0.5s ease;
}
.form-group input:focus + .label-name .content-name,
.form-group input:valid + .label-name .content-name {
transform: translateY(-120%);
font-size: 14px;
color: #5fa8d3;
}
<div class="form-group">
<input type="text" class="form-control" name='input-name' required>
<label for="input-name" class='label-name'>
<span class='content-name'>Enter your name</span>
</label>
</div>

Related

"valid" pseudo class is not working on "required" email input if the input text format is NOT "email"

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>
Consider :focus and :placeholder-shown. The first one will activate when you are at the input and the second one when there is at least some content. Don't forget to add an empty placeholder or the trick won't work
.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:not(:placeholder-shown) +.label-name .content-name,
.form-group input:focus +.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" placeholder=" " 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>

Why is there some excess scale at the bottom? how to remove those?

There's a little royalblue background appearing (between border-bottom: 2px solid white; & ::after element) when I unfocus.
I don't know why is that happening.
body {
background-color: royalblue;/*#f0f0f0;*/
}
label {
font-family: 'Montserrat', sans-serif;
font-size: 14px;
z-index: -1;
border: 0;
color: white;
position: relative;
}
.head {
color: white;
margin-left: 44%;
font-family: monospace;
font-size: 25px;
}
/*.content {
margin-top: 10%;
margin-left: 41%;
}*/
.password {
margin-top: 8%;
}
form {
position: relative;
}
input {
position: absolute;
font-family: 'Montserrat', sans-serif;
font-size: 15px;
background: transparent;
border: 0; /* BORDER yes/no */
border-bottom: 2px solid white;
background: transparent;
outline: 0;
height: 25px;
width: 180px;
z-index: 1;
margin-top: 5px;
}
/*input:focus {
outline: 1;
}*/
label::after {
content: '';
position: absolute;
top: -2px;
left: 0;
width: 180px;
height: 25px;
border-radius: 2px;
transition: transform .3s;
}
label::after{
z-index: -1;
background: beige; /*#a86bf;*/
transform: scale3d(1, 0, 1);
transform-origin: 0% 0%;
}
input:focus {
border-radius: 1px;
}
input:focus + label::after,
input:valid + label::after {
transform: scale3d(1, -1, 1);
transition-timing-function: linear;
}
span {
position: relative;
margin-top: -30px;
display: block;
padding: .6em 0;
padding-left: -5px;
transition: top .5s ease, font-size .5s ease;
/* transition: transform 1s 2s;*/
top: 0;
}
input:focus + label > span,
input:valid + label > span {
top: -20px;
font-size: 11px;
padding-bottom: 15px;
}
/* font-family: monospace;*/
/*transform: translate3d(0, -80%, 0); */
/* transition-timing-function: linear;*/
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
<link href="https://fonts.googleapis.com/css?family=Montserrat" rel="stylesheet">
<title>Test</title>
</head>
<body>
<p class="head">Sign In</p>
<form>
<div class="content">
<div class="username">
<input type="text" name="name" class="user-input" id="user" required /> <!--input field-->
<label class="user-label" for="user"><span>Username</span></label>
</div>
<div class="password">
<input type="text" name="name" class="pass-input" id="pass" required /> <!-- input field -->
<label class="pass-label" for="pass"><span>Password</span></label>
</div>
</div>
</form>
</body>
</html>
Update:
I changed to top: 1px;, also change border-bottom to black, now this is the result (full code). Why is there some excess scale at the bottom? how to remove those?
You have a top: -2px on label, and your problem is when you blur, so a solution is move top: -2px to input:focus + label::after and input:focus + label::after, so you dont have that gap when its not focused or validated
body {
background-color: royalblue;/*#f0f0f0;*/
}
label {
font-family: 'Montserrat', sans-serif;
font-size: 14px;
z-index: -1;
border: 0;
color: white;
position: relative;
}
.head {
color: white;
margin-left: 44%;
font-family: monospace;
font-size: 25px;
}
/*.content {
margin-top: 10%;
margin-left: 41%;
}*/
.password {
margin-top: 8%;
}
form {
position: relative;
}
input {
position: absolute;
font-family: 'Montserrat', sans-serif;
font-size: 15px;
background: transparent;
border: 0; /* BORDER yes/no */
border-bottom: 2px solid white;
background: transparent;
outline: 0;
height: 25px;
width: 180px;
z-index: 1;
margin-top: 5px;
}
/*input:focus {
outline: 1;
}*/
label::after {
content: '';
position: absolute;
left: 0;
width: 180px;
height: 25px;
border-radius: 2px;
transition: transform .3s;
}
label::after{
z-index: -1;
background: beige; /*#a86bf;*/
transform: scale3d(1, 0, 1);
transform-origin: 0% 0%;
}
input:focus {
border-radius: 1px;
}
input:focus + label,
input:valid + label {
top: -2px;
}
input:focus + label::after,
input:valid + label::after {
transform: scale3d(1, -1, 1);
transition-timing-function: linear;
}
span {
position: relative;
margin-top: -30px;
display: block;
padding: .6em 0;
padding-left: -5px;
transition: top .5s ease, font-size .5s ease;
top: 0;
}
input:focus + label > span,
input:valid + label > span {
top: -20px;
font-size: 11px;
padding-bottom: 15px;
}
/* font-family: monospace;*/
/*transform: translate3d(0, -80%, 0); */
/* transition-timing-function: linear;*/
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
<link href="https://fonts.googleapis.com/css?family=Montserrat" rel="stylesheet">
<title>Test</title>
</head>
<body>
<p class="head">Sign In</p>
<form>
<div class="content">
<div class="username">
<input type="text" name="name" class="user-input" id="user" required /> <!--input field-->
<label class="user-label" for="user"><span>Username</span></label>
</div>
<div class="password">
<input type="text" name="name" class="pass-input" id="pass" required /> <!-- input field -->
<label class="pass-label" for="pass"><span>Password</span></label>
</div>
</div>
</form>
</body>
</html>
you have an extra code, you can see here in comment section
label::after {
content: '';
position: absolute;
/*top: -2px;*/
left: 0;
width: 180px;
height: 25px;
border-radius: 2px;
transition: transform .3s;
}
Add top:1px on label::after See Below.
label::after {
content: '';
position: absolute;
left: 0;
top: 1px;
width: 180px;
height: 25px;
border-radius: 2px;
transition: transform .3s;
}

Transition Origins

I am currently making a pretty simplistic login page. I would like that the transition between .form input[type="text"]:focus, .form input[type="password], instead of gradually fading the color in, it swooshes the new color from left to right.
Here is my code:
.form input[type="text"],
.form input[type="password"] {
margin-top: 0;
margin-bottom: 5px;
border: none;
border-bottom-width: 2px;
border-bottom-style: solid;
border-bottom-color: black;
background: transparent;
outline: none;
height: 2.5vh;
color: black;
border-radius: 0;
font-size: 100%;
transition-property: border-bottom-color;
transition-duration: 350ms;
transition-timing-function: cubic-bezier(0.4, 0.0, 0.2, 1);
}
.form input[type="text"]:focus,
.form input[type="password"]:focus {
border-bottom-color: #66bb6a;
}
<form class="form">
<input type="text" name="" placeholder="example#example.com">
</form>
Here is a JS Fiddle: https://jsfiddle.net/juja15ro/
I was able to do it but with javascript.
const inputs = document.querySelectorAll('.input-container input');
inputs.forEach((input) => {
input.addEventListener('focus', () => {
input.parentElement.classList.add('focused');
})
input.addEventListener('blur', () => {
input.parentElement.classList.remove('focused');
})
})
.input-container {
position: relative;
display: inline-block;
}
.input-container:after {
content: '';
position: absolute;
bottom: 0;
left: 0;
height: 2px;
width: 0;
background-color: #000;
transition: .24s ease-out;
}
.input-container input {
border: none;
background: transparent;
border-bottom: 1px solid #ccc;
outline: none;
}
.input-container.focused:after {
width: 100%;
}
<div class="input-container">
<input type="text" placeholder="Name">
</div>
I have created a span(input bar) and added :before and :after property to it and for the left to right movement, before should be 0% and after should be 100% .(Also try before to 50% and after to 50% and see movement effect starting from center) Here's my code
*:focus {
outline: none;
}
input {
display: block;
border: none;
border-bottom: 1px solid #000;
font-family: Trebuchet MS;
background: none;
}
.inputBar {
position: relative;
display: block;
width: 290px;
}
.inputBar:before,
.inputBar:after {
content: "";
display: block;
position: absolute;
bottom: 0;
width: 0;
background: #66bb6a;
height: 2px;
transition: all 0.2s ease;
}
.inputBar:after {
right: 100%;
}
.inputBar:before {
left: 0%;
}
input:focus~.inputBar:before,
input:focus~.inputBar:after {
width: 50%;
}
<form class="form">
<input type="text" name="" placeholder="example#example.com">
<span class="inputBar"></span>
</form>

Custom checkboxes move slightly when selected

I modified the checkboxes in my project to look more aligned with the rest of the design but I have a problem: whenever selected the label of the checkbox moves slightly.
input[type="checkbox"] {
display: none !important;
}
input[type="checkbox"]+label:before {
position: relative;
content: " ";
display: inline-block;
width: 22px;
height: 22px;
border: 1px solid grey;
top: 4px;
margin: 0 10px 0 0;
}
input[type="checkbox"]:checked+label:before {
position: relative;
content: "✔";
display: inline-block;
width: 22px;
height: 22px;
border: 1px solid grey;
top: 4px;
margin: 0 10px 0 0;
}
<input type="checkbox" />
<label>Click to accept</label>
Here's the result:
And here's what happens if I select it:
What am I doing wrong?
Nowadays and for awhile you can fix this if you set the parent to display:flex
input[type="checkbox"] {
display: none !important;
}
label {
display: flex;
/* just to vertically the text with the box */
align-items: center
}
input[type="checkbox"]+label::before {
content: "";
display: block;
width: 22px;
height: 22px;
border: 1px solid grey;
margin: 0 10px 0 0;
}
input[type="checkbox"]:checked+label::before {
content: "✔";
/* just to center inside the box */
display: grid;
place-content: center;
}
<input id="input" type="checkbox" />
<label for="input">Click to accept</label>
OLD ANSWER
To fix the "moving" you need to:
set vertical-align: some value in label::before I have choose bottom.
And to align the "✔" (in case it doesn't - snippet isn't), you need to:
add text-align:center and line-height:22px (same as the height) in :checked+label::before
input[type="checkbox"] {
display: none !important;
}
input[type="checkbox"]+label::before {
position: relative;
content: " ";
display: inline-block;
vertical-align: bottom;
width: 22px;
height: 22px;
border: 1px solid grey;
top: 4px;
margin: 0 10px 0 0;
}
input[type="checkbox"]:checked+label::before {
content: "✔";
text-align: center;
line-height: 22px;
}
<input id="input" type="checkbox" />
<label for="input">Click to accept</label>
NB: In both answers I removed duplicated properties and you're missing the for attribute in label to match id in input, otherwise you can't click in the pseudo checkbox, only in the label
You can see another way here.
See below working example:
/*--CSS--*/
input[type="checkbox"] {
-webkit-appearance: none;
background-color: transparent;
-webkit-rtl-ordering: logical;
user-select: text;
cursor: pointer;
padding: 1px;
border-width: 0;
border-style: inset;
border-color: initial;
border-image: initial;
float: left;
margin: 0 25px 0 0;
position: relative;
}
input[type="checkbox"]:after {
-webkit-transition: all 0.3s ease-in-out;
-moz-transition: all 0.3s ease-in-out;
transition: all 0.3s ease-in-out;
content: "";
position: absolute;
left: 0;
z-index: 1;
width: 16px;
height: 16px;
border: 1px solid #c0c0c0;
top:0;
}
input[type="checkbox"]:before {
-webkit-transition: all 0.3s ease-in-out;
-moz-transition: all 0.3s ease-in-out;
transition: all 0.3s ease-in-out;
content: "";
position: absolute;
left: 0;
z-index: 1;
width: 16px;
height: 16px;
border: 1px solid #c0c0c0;
top:0;
opactity:0;
}
input[type="checkbox"]:checked:before {
-webkit-transform: rotate(-45deg);
-moz-transform: rotate(-45deg);
-ms-transform: rotate(-45deg);
-o-transform: rotate(-45deg);
transform: rotate(-45deg);
height: 5px;
border-color: #009688;
border-top-style: none;
border-right-style: none;
outline: none;
opacity: 1;
width: 12px;
top: 3px;
left: 3px;
}
input[type="checkbox"]:focus{outline:0;}
<!--HTML-->
<input type="checkbox" />
<label>Click to accept</label>
I have used a flexbox for the label to align the items vertically. Adding text-align:center when the checkbox is checked, ensures the marker is horizontally centered.
label {
display: flex;
align-items: center;
}
input[type="checkbox"] {
display: none;
}
input[type="checkbox"]+label:before {
content: " ";
display: inline-block;
width: 22px;
height: 22px;
border: 1px solid grey;
margin-right: 0.5em;
}
input[type="checkbox"]:checked+label:before {
content: "✔";
display: inline-block;
width: 22px;
height: 22px;
border: 1px solid grey;
margin-right: 0.5em;
text-align: center;
}
<input type="checkbox" id="accept" />
<label for="accept">Click to accept</label>
you can try this, this is working
input[type="checkbox"] {
position: absolute;
width: 100%;
height: 100%;
opacity: 0;
}
input[type="checkbox"] + label:before {
position: relative;
content: " ";
display: inline-block;
width: 22px;
height: 22px;
border: 1px solid grey;
top: 4px;
margin: -8px 10px 0 0;
vertical-align: middle;
}
input[type="checkbox"]:checked + label:before {
content: "✔";
text-align: center;
line-height: 22px;
}
<input type="checkbox"/>
<label>Click to accept</label>

How to move placeholder to top on focus AND while typing?

I want the placeholder to move to the top when the textbox is on focus and also while the user is typing.
I'm not sure if this is just html/css or any javascript too.
My current css looks like this, and I have no js code yet:
input:focus::-webkit-input-placeholder {
font-size: .75em;
position: relative;
top: -15px;
transition: 0.2s ease-out;
}
input::-webkit-input-placeholder {
transition: 0.2s ease-in;
}
input[type="text"]:focus, input[type="password"]:focus {
height: 50px;
padding-bottom: 0px;
transition: 0.2s ease-in;
}
input[type="text"], input[type="password"] {
height: 50px;
transition: 0.2s ease-in;
}
It almost does the work but the placeholder disappears when I start typing. I'm using twitter-bootstrap, if that makes anything easier!
Thanks.
You could do it like this
HTML:
<div>
<input type="text" class="inputText" />
<span class="floating-label">Your email address</span>
</div>
CSS:
input:focus ~ .floating-label,
input:not(:focus):valid ~ .floating-label{
top: 8px;
bottom: 10px;
left: 20px;
font-size: 11px;
opacity: 1;
}
.inputText {
font-size: 14px;
width: 200px;
height: 35px;
}
.floating-label {
position: absolute;
pointer-events: none;
left: 20px;
top: 18px;
transition: 0.2s ease all;
}
Working JSFiddle here https://jsfiddle.net/273ntk5s/2/
.user-input-wrp {
position: relative;
width: 50%;
}
.user-input-wrp .inputText{
width: 100%;
outline: none;
border:none;
border-bottom: 1px solid #777;
box-shadow: none !important;
}
.user-input-wrp .inputText:focus{
border-color: blue;
border-width: medium medium 2px;
}
.user-input-wrp .floating-label {
position: absolute;
pointer-events: none;
top: 18px;
left: 10px;
transition: 0.2s ease all;
}
.user-input-wrp input:focus ~ .floating-label,
.user-input-wrp input:not(:focus):valid ~ .floating-label{
top: 0px;
left: 10px;
font-size: 13px;
opacity: 1;
}
<h1>The floating label</h1>
<div class="user-input-wrp">
<br/>
<input type="text" class="inputText" required/>
<span class="floating-label">Your email address</span>
</div>
Modified the code from #user1846747 a little.
Only using HTML and css
.searchformfld{
position: relative;
margin: 5px 0px;
}
.searchformfld label{
position: absolute;
padding-left: 10px;
top:15px;
cursor: text;
}
.searchformfld input:focus + label,.searchformfld input:not(:placeholder-shown) + label{
opacity:1;
transform: scale(.9) translateY(-100%) translateX(-10px);
color:#000;
}
.searchformfld input:focus{
border:1px solid #000;
outline-color: #000;
}
.searchformfld{
padding: 15px;
margin:15px 0px;
}
.searchformfld input{
width:100%;
padding-left: 10px;
}
.searchformfld label,.searchformfld input{
transition: all 0.2s;
transition-timing-function: ease;
transition-timing-function: cubic-bezier(0.25, 0.1, 0.25, 1);
opacity:0.5;
}
<div class="searchformfld">
<input type="text" class="candidateName" id="candidateName" name="candidateName" placeholder=" "/>
<label for="candidateName">Candidate name</label>
</div>
You can try the below code. It only uses HTML and CSS and does not reply on Javascript or component libraries:
.text-field {
position: relative;
margin: 10px 2.5px 20px 2.5px;
}
input {
display: inline-block;
border: thin solid #fafafa;
border-bottom: solid medium #999;
color: #444;
background-color: #fafafa;
padding: 10px 10px 10px 10px;
border-top-left-radius: 10px;
border-top-right-radius: 10px;
}
input:focus {
border: thin solid #32cd32;
border-bottom: solid medium #32cd32;
background-color:#fff;
}
label {
color: #999;
position: absolute;
pointer-events: none;
left: 10px;
top: 10px;
transition: 0.2s;
}
input:focus ~ label, input:valid ~ label {
top: -10px;
left: 15px;
font-size: small;
color: #32cd32;
background-color:#fff;
padding:0 5px 0 5px;
}
<div class="text-field">
<input type="text" required>
<label>Input field 1</label>
</div>
<div class="text-field">
<input type="text" required>
<label>Input field 2</label>
</div>
span{
display:block;
}
input:focus::-webkit-input-placeholder { color:transparent; }
input:focus:-moz-placeholder { color:transparent; } /* FF 4-18 */
input:focus::-moz-placeholder { color:transparent; } /* FF 19+ */
input:focus:-ms-input-placeholder { color:transparent; } /* IE 10+ */
<script src="http://code.jquery.com/jquery-3.1.1.min.js"></script>
<script>
$(document).ready(function() {
$('input').focus(function(){
placeholder = $(this).attr('placeholder');
if(placeholder != undefined){
$(this).parent().prepend('<span class="input-placeholder">'+placeholder+'</span>');
}
});
$('input').blur(function(){
$(this).parent().find('.input-placeholder').remove();
});
});
</script>
<div>
<input type="text" class="inputText" placeholder="Email adress" required/>
</div>
The solution I want to propose deals with an input with the movement of the placeholder without the need for the required attribute
.inputField {
position: relative;
}
.inputField input {
padding: 8px 20px;
padding-top: 18px;
border: 1.8px solid rgba(107, 107, 107, 0.4);
border-radius: 3px;
width: 50%;
color: black;
}
.inputField input:focus {
border: 1.8px solid #6b6b6b;
outline: none;
}
.inputField span {
pointer-events: none;
opacity: 0.5;
position: absolute;
padding-left: 20px;
left: 0;
top: 50%;
-webkit-transform: translateY(-50%);
transform: translateY(-50%);
cursor: text;
}
.inputField input:focus+span,
.inputField input:not(:placeholder-shown)+span {
top: 7px;
-webkit-transform: scale(0.7) translateY(-10%) translateX(-8.5px);
transform: scale(0.7) translateY(-10%) translateX(-8.5px);
}
.inputField input,
.inputField span {
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
-webkit-transition: all 0.2s;
transition: all 0.2s;
-webkit-transition-timing-function: cubic-bezier(0.25, 0.1, 0.25, 1);
transition-timing-function: cubic-bezier(0.25, 0.1, 0.25, 1);
}
<div class="inputField">
<input type="text" placeholder=" " />
<span>Placeholder</span>
</div>
That site isn't moving the placeholder, but placing a div (.floating-label) over the input, so when the input is focused the div just animates to be over the input. The key part here is using pointer-events: none; in the floating div, so when you click it the event goes through it to the input box behind it.
if your Floating label is not working when required attribute is removed, try this: using input:not(:placeholder-shown)
input:focus ~ .floating-label,
input:not(:placeholder-shown) ~ .floating-label{
top: 8px;
bottom: 10px;
left: 20px;
font-size: 11px;
opacity: 1;
}
.inputText {
font-size: 14px;
width: 200px;
height: 35px;
}
.floating-label {
position: absolute;
pointer-events: none;
left: 20px;
top: 18px;
transition: 0.2s ease all;
}
<div>
<input placeholder="" type="text" class="inputText" />
<span class="floating-label">Your email address</span>
</div>