input css动画

149 阅读1分钟

html

<div class="login">
    <input type="text" class="user">
    <lable for="" class="text">user</lable>
    <lable for="" class="underline"></lable>
 </div>

CSS

body{
  background-image: linear-gradient(to right, #ff9569 0%,#e92758 100%);
}

.login {
  position: relative;
  width: 500px;
  height: 150px;
  background-image: linear-gradient(45deg, #ff9a9e 0%, #fad0c4 99%,#fad0c4 100%);
  border-radius: 10px;
  margin: 300px auto;
}

.user{
  width: 300px;
  height: 30px;
  background-color: transparent;
  border: 0;
  outline: none;
  border-bottom: 2px solid #fff;
  font-size: 20px;
  margin-top: 60px;
  margin-left: 50px;
  color: #000;
  font-weight: 100;
}

.text{
  position: absolute;
  top: 60px;
  left: 50px;
  transition: all .5s;
  font-size: 20px;
  color: rgb(246,68,65);
  font-weight: 100;
}

.underline {
  position: absolute;
  top: 92px;
  left: 50px;
  display: block;
  width: 305px;
  height: 2px;
  transform: scaleX(0);
  transition: all .3s ease-in;
}

.user:focus ~ .text {
  top: 45px;
  font-size: 14px;
}

.user:focus ~ .underline{
  transform: scale(1);
  background-color: rgb(136,61,136);
  transform-origin: center center;
}