表單動畫特效-1

by birdie2019

HTML

<form>
  <input type="text" id="username" required>
  <label for="username">Username</label>
</form>

CSS

/* basic */

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-size: 16px;
  color: #fff;
}

body {
  background-color: #000;
}

form {
  width: 400px;
  margin: 100px auto;
  position: relative;
}

/* main */

input {
  width: 100%;
  padding: 10px 0;
  border: none;
  border-bottom: 1px solid #fff;
  outline: none;
  background-color: transparent;
  transition: all 0.5s;
}

#username:focus {
  border-bottom: 1px solid aqua;
}

#username ~ label {
  color: #fff;
  padding: 10px 0;
  position: absolute;
  top: 0;
  left: 0;
  transition: all 0.5s;
}

#username:focus ~ label, #username:valid ~ label {
  color: aqua;
  font-size: 12px;
  top: -25px;
  left: 0;
}