-1

I'm trying to move the label above the input field when focus like this.

But in my other code, it only changes font-size and is not moving up. What am I missing?

I use the same CSS code for both:

CSS

input:focus + label > span {
    font-size: 12px;
    transform: translate3d(0, -80%, 0);
    transition-timing-function: cubic-bezier(0.2, 1, 0.3, 1);
}
fiza khan
  • 1,280
  • 13
  • 24
yalpsid
  • 235
  • 1
  • 13
  • Possible duplicate of [How to move placeholder to top on focus AND while typing?](https://stackoverflow.com/questions/35942247/how-to-move-placeholder-to-top-on-focus-and-while-typing) – Neeraj Kamat Sep 08 '18 at 05:25
  • You should include the code with the question. – jww Sep 08 '18 at 12:56

2 Answers2

0

Target The Span Within The Lable

If you target the span contained in the label, you can control it with the below code.

input + label > span {
  position: relative;
  display: block;
  bottom: -1em
}

Your code needs a lot of work, but start here:

body {
  background-color: #f0f0f0;
}

form {
  margin-left: 40%;
  margin-top: 11%;
}
label {
  font-family: monospace; 'Montserrat', sans-serif;
  font-size: 19px;
  margin-left: -26%;
  z-index: -1;
 /* border: 5px solid black;*/ 
}

.head {
margin-left: 43%;
margin-top: 5%;
font-size: 25px;
font-family: monospace;

}

form {
position: relative; }


.input-field {
  display:block;
  background: transparent;
  border-width: 2px;
  border-top: 0;
  border-left: 0;
  border-right: 0;
  border: 0;
  background: transparent;
  outline: 0;
  height: 23px;
  border-color: black;
  width: 130px;
  z-index: 1;
  margin-left: 0%;
} 


/*input:focus { 
transform: scale3d(1, 1, 1); 
transition: width 5s; 
transition-delay: 3s; 
transition-timing-function: cubic-bezier(0.2, 1, 0.3, 1); 
z-index: -1; 
background: green; /* ::after background *
} */


label::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 0;
  width: 30%;
  height: 20%;
  transition: transform 0.8s;
}


label::after {
  z-index: -1;
  background: green;  /* ::after background */
  transform: scale3d(1, 0.1, 1);
  transform-origin: 0% 0%;
}


input:focus + label::after {
  transform: scale3d(1, -2, 1);
  transition-timing-function: linear;
}

input:focus + label > span {
  
  font-size: 14px;
  transform: translate3d(0, -200%, 0);
  transition-timing-function: cubic-bezier(0.2, 1, 0.3, 1);
  
}
input + label > span {
  position: relative;
  display: block;
  bottom: -1em
}
<!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="username"> 
      
      <input type="text" name="name" class="input-field" id="user"/> <!--input filed-->
      <label for="user">
       <span class="username">Username</span>
      </label>
    </div> 
  
</form>

</body>
</html
Electron
  • 969
  • 1
  • 8
  • 22
0

Filtered Code. You can Use This Code. This is working Fine.

.object {
  position: relative;
  z-index: 1;
  display: inline-block;
  width: 300px; /* input field width */
}

.input {
  position: relative;
  display: block;
  float: right;
  width: 30%;
  border: none;
  background: black;
  color: yellow; /* font color when typing */
  font-family: monospace;
   /* for box shadows to show on iOS */
}

.input:focus {
  outline: none;
}

.label {
  display: inline-block;
  color: black; /* label font color */
  font-size: 18px;
  font-family: monospace;
}

.label-content {
  position: relative;
  display: block;
  padding: .6em 0;
}
.input--jiro {
  padding: 0.85em 0.5em;
  width: 100%;          /* input width when focus */
  background: blue    ; /* input background color */
  opacity: 0;
  transition: opacity 0.3s;
}
.label-content--jiro {
  transition: transform 0.3s 0.3s;
}
.label--jiro {
  position: absolute;
  left: 0;
  padding: 0 0.85em;
  width: 120%;          /* underline width */
  height: 100%;
}
label::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 0;
  width: 80%;
  height: 100%;
  transition: transform .8s;
}

label::after {
  z-index: -1;
  background: green;  /* ::after background */
  transform: scale3d(1, 0.1, 1); 
  transform-origin: 0% 0%; /*  0% 50%; * for middle */ 
}

input:focus + label::after {
  transform: scale3d(1, -1, 1);
  transition-timing-function: linear;
}

input:focus + label > span {
  font-size: 12px;
  transform: translate3d(0, -80%, 0);
  transition-timing-function: cubic-bezier(0.2, 1, 0.3, 1);
}
<p class="head">Sign In</p>
 <section>
    
    <span class="object">

     <input class="input input--jiro" type="text" id="input-10" />  <!-- input field -->

                  <label class="label label--jiro" for="input-10">
                  <span class="label-content label-content--jiro">Username</span> <!-- Label -->
               </label>
    </span>
   </section>
Hariom Singh
  • 1,420
  • 1
  • 8
  • 21