Skip to content Skip to sidebar Skip to footer

Keep Input Placeholder Always Visible

I am trying to style all the inputs in my website in a way that when they have a value or have focus the palceholder becomes the title of the input (it moves to the top of the inpu

Solution 1:

It cant be done using just the placeholder. Here is sample.

body {
  padding: 25px10px
}
* {
  margin: 0
}
.fieldOuter {
  position: relative;
  margin: 0030px0;
  font-family: impact;
  font-size: 16px
}
.fieldOuterinput {
  padding: 10px;
  width: 250px;
  transition: all 1s;
  border: 2px solid #999;
  font-size: 17px;
  color: #666
}
.fieldOuterlabel {
  position: absolute;
  left:0px;
  top: 0;
  line-height:15px;
  transition: all 0.5s;
  overflow: hidden;
  color: #999;
  white-space: nowrap;
  z-index: 1;
  opacity: 0;
}
.fieldOuterinput:focus + label {
  opacity: 1;
  top: -18px;  
}
.fieldOuterinput:focus {
  outline: none;
  border-color: rgba(82, 168, 236, 0.8);
}
<divclass="fieldOuter"><inputid="Name"placeholder="Name"type="text" /><labelfor="Name">Name</label></div><divclass="fieldOuter"><inputid="LastName"placeholder="Last Name"type="text" /><labelfor="LastName">Last Name</label></div>

Post a Comment for "Keep Input Placeholder Always Visible"