0
点赞
收藏
分享

微信扫一扫

有趣的input输入框

驚鴻飛雪 2022-04-14 阅读 126
css

有趣的input输入框

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

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>有趣的input输入框</title>
    <link rel="stylesheet" href="../css/03.css">
</head>

<body>

    <div class="wrapper">
        <div class="input-data">
            <!-- required :布尔值。表示此值为必填项或者提交表单前必须先检查该值 -->
            <input type="text" required>
            <div class="underline"></div>
            <label>您的姓名</label>
        </div>
    </div>
</body>

</html>
* {
  margin: 0;
  padding: 0;
  outline: none;
  box-sizing: border-box;
}
body {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  background: linear-gradient(200deg, #0c3483, #a2b6df);
}
body .wrapper {
  width: 450px;
  background-color: #fff;
  padding: 40px;
  box-shadow: 0, 0, 10px, rgba(0, 0, 0, 0.1);
  border-radius: 8px;
}
body .wrapper .input-data {
  position: relative;
  width: 100%;
  height: 40px;
}
body .wrapper .input-data input {
  width: 100%;
  height: 100%;
  border: none;
  font-size: 17px;
  border-bottom: 2px solid #c0c0c0;
  /*输入框获得焦点时*/
}
body .wrapper .input-data input:focus ~ label,
body .wrapper .input-data input:valid ~ label {
  transform: translateY(-25px);
  font-size: 15px;
  color: #2c6fdb;
}
body .wrapper .input-data input:focus ~ .underline,
body .wrapper .input-data input:valid ~ .underline {
  transform: scaleX(1);
}
body .wrapper .input-data label {
  position: absolute;
  bottom: 10px;
  left: 0;
  color: #999;
  pointer-events: none;
  transition: all 0.3S ease;
}
body .wrapper .input-data .underline {
  position: absolute;
  bottom: 0px;
  width: 100%;
  height: 2px;
  background-color: #2c6fdb;
  /*沿X轴缩小*/
  transform: scaleX(0);
  transition: all 0.3S ease;
}

举报

相关推荐

0 条评论