文章数量
36
访客量
4952
访问量
9817

css特效之文本动画登录表单

阅读量:382
更新时间:2023-10-12 23:59:12

效果预览:效果预览
源码下载:关注公众号【RMRF】,回复【css14】可获取源码

HTML

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>文本动画登录表单</title>
  <link rel="stylesheet" href="./css/index.css">
</head>

<body>
  <div id="app">
    <div class="login">
      <form>
        <div class="input-item">
          <input type="text" name="" required="">
          <label>Username</label>
        </div>
        <div class="input-item">
          <input type="password" name="" required="">
          <label>Password</label>
        </div>
        <div class="action">
          <button>Login</button>
        </div>
      </form>
    </div>
  </div>
</body>

</html>

CSS

* {
  padding: 0px;
  margin: 0px;
}

#app {
  height: 100vh;
  width: 100%;
  background-color: #202020;
}

.login {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 400px;
  padding: 40px;
  transform: translate(-50%, -50%);
  background: #202020;
  box-sizing: border-box;
  box-shadow: 0 15px 25px rgba(0, 0, 0, 0.6);
  border-radius: 10px;

}

.login .input-item {
  position: relative;
}

.login .input-item input {
  width: 100%;
  padding: 10px 0;
  font-size: 16px;
  color: #666;
  margin-bottom: 30px;
  border: none;
  border-bottom: 1px solid #666;
  outline: none;
  background: transparent;
}

.login .input-item label {
  position: absolute;
  top: 0;
  left: 0;
  padding: 10px 0;
  font-size: 16px;
  color: #666;
  pointer-events: none;
  transition: .5s;
}

.login .input-item input:focus~label,
.login .input-item input:valid~label {
  top: -20px;
  left: 0;
  color: #e5e5e5;
  font-size: 12px;
}

.action button {
  width: 100%;
  border: 1px solid #dcdfe6;
  border-radius: 4px;
  cursor: pointer;
  transition: 0.1s;
  padding: 8px 15px;
  color: #fff;
  background-color: #409eff;
  border-color: #409eff;
}

.action button:hover {
  background-color: rgba(64, 160, 255, 0.7);
}

.action button:active {
  background-color: rgba(64, 160, 255, 0.8);
}