<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" href="css/login.css">
<title>登录</title>
</head>
<body>
<img src="img/bg1.png" class="bg1">
<div class="container">
<div class="login-box">
<form action="">
<img src="img/userlogo.png" class="user">
<h2>WELCOME</h2>
<div class="input-group">
<div class="icon">
<i class="fa fa-user"></i>
</div>
<div>
<h5>用户名</h5>
<input type="text" class="userinput">
</div>
</div>
<div class="input-group">
<div class="icon">
<i class="fa fa-lock"></i>
</div>
<div>
<h5>密码</h5>
<input type="password" class="userinput">
</div>
</div>
<a href="register.html">注册</a>
<input type="submit" class="btn" value="登录">
</form>
</div>
</div>
<script src="js/style.js" type="text/javascript"></script>
</body>
</html>
*{
padding: 0;
margin: 0;
box-sizing: border-box;
}
.bg1{
position: fixed;
height: 100%;
width: 100%;
right: 0;
bottom: 0;
z-index: -1;
}
.container{
display: flex;
align-items: center;
text-align: center;
justify-content: center;
width: 100vw;
height: 100vh;
}
form{
width: 360px;
}
.user{
width: 100px;
}
h2{
font-size: 46px;
margin: 15px 0;
color: #999;
cursor: default;
}
.input-group{
position: relative;
display: grid;
grid-template-columns: 8% 92%;
margin: 30px 0;
border-bottom: 2px solid #d9d9d9;
}
.input-group:nth-child(1){
margin-bottom: 4px;
}
.input-group:before,.input-group:after{
content: '';
position: absolute;
bottom: -2px;
width: 0;
height: 2px;
background-color: #38d39f;
transition: 0.5s;
}
.input-group:after{
right: 50%;
}
.input-group:before{
left: 50%;
}
.icon{
display: flex;
justify-content: center;
align-items: center;
}
.icon i{
color: #d9d9d9;
transition: 0.5s;
}
.input-group > div{
position: relative;
height: 45px;
}
h5{
position: absolute;
left: 10px;
top: 50%;
transform: translateY(-50%);
color: #d9d9d9;
font-size: 18px;
transition: .3s;
}
.input-group.focus .icon i{
color: #38d39f;
}
.input-group.focus div h5{
top: -5px;
font-size: 15px;
}
.input-group.focus:after,.input-group.focus:before{
width: 50%;
}
.userinput{
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
border: none;
outline: none;
background: none;
padding: 5px 10px;
font-size: 17px;
color: #555555;
font-family: 'Roboto', sans-serif;
}
a{
display: block;
text-align: right;
text-decoration: none;
color: #999;
font-size: 15px;
}
a:hover{
color: #38d39f;
}
.btn{
display: block;
width: 100%;
height: 50px;
border-radius: 25px;
margin: 20px 0;
font-size: 20px;
outline: none;
border: none;
cursor: pointer;
color: #fff;
background-image: linear-gradient(to right,#32be8f,#38d39f,#32be8f);
background-size: 200%;
transition: 0.5s;
}
.btn:hover{
background-position: right;
}
@media screen and (max-width: 1080px) {
.container{
grid-gap: 9rem;
}
}
@media screen and (max-width: 1024px) {
form{
width: 290px;
}
form h2{
font-size: 36px;
margin: 8px 0;
}
}
@media screen and (max-width: 768px) {
.bg1{
display: none;
}
.bg2{
display: none;
}
.container{
grid-template-columns: 1fr;
}
.login-box{
justify-content: center;
}
}
const inputs = document.querySelectorAll(".userinput");
function focusFunction(){
let parentNode = this.parentNode.parentNode;
parentNode.classList.add('focus');
}
function blurFunction(){
let parentNode = this.parentNode.parentNode;
if(this.value == ''){
parentNode.classList.remove('focus');
}
}
inputs.forEach(input=>{
input.addEventListener('focus',focusFunction);
input.addEventListener('blur',blurFunction);
});
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" href="css/login.css">
<title>登录</title>
</head>
<body>
<img src="img/bg1.png" class="bg1">
<div class="container">
<div class="login-box">
<form action="login.html">
<img src="img/userlogo.png" class="user">
<h2>WELCOME</h2>
<div class="input-group">
<div class="icon">
<i class="fa fa-user"></i>
</div>
<div>
<h5>用户名</h5>
<input type="text" class="userinput">
</div>
</div>
<div class="input-group">
<div class="icon">
<i class="fa fa-lock"></i>
</div>
<div>
<h5>密码</h5>
<input type="password" class="userinput">
</div>
</div>
<div class="input-group">
<div class="icon">
<i class="fa fa-lock"></i>
</div>
<div>
<h5>确认密码</h5>
<input type="password" class="userinput">
</div>
</div>
<input type="submit" class="btn" value="注册">
</form>
</div>
</div>
<script src="js/style.js" type="text/javascript"></script>
</body>
</html>