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="./index.css">
</head>
<body>
<div class="box">
<form action="#" class="login_form">
<h2>登录</h2>
<input type="text" name="username" required="required" placeholder="用户名">
<input type="password" name="pwd" required="required" placeholder="密码">
<button type="submit">LOGIN</button>
</form>
</div>
</body>
</html>
CSS文件
html,
body{
margin: 0;
padding: 0;
}
.box{
display: flex;
height: 100vh;
width: 100vw;
justify-content: center;
align-items: center;
background: url(./image/login.jpg) fixed no-repeat;
background-size: cover;
}
.login_form{
display: flex;
position: relative;
width: 240px;
height: 220px;
/* 将元素纵向展示 */
flex-direction: column;
padding: 40px;
text-align: center;
/* 继承父元素的属性 */
background: inherit;
border-radius: 18px;
overflow: hidden;
z-index: 100;
}
/* 背景图片局部模糊模糊区域 */
.login_form::after{
content: "";
position: absolute;
top:-10px;
left: -10px;
width: calc(100% + 20px);
height:calc(100% + 20px);
border-radius: inherit;
box-shadow:inset 0 0 0 6px rgba(255,255,255,.25);
background: inherit;
z-index: -1;
filter: blur(6px);
overflow: hidden;
}
.login_form h2{
font-size: 18px;
font-weight:400;
color: #3d5245;
}
.login_form input,
.login_form button{
margin: 6px 0;
height: 30px;
border: none;
border-radius: 4px;
background-color: rgba(255,255,255,.3);
color: #3d5245;
outline: none;
}
.login_form input::placeholder{
color: #3d5245;
}
.login_form button{
/* position: relative; */
margin-top: 24px;
background-color: rgba(41, 124, 73, 0.2);
color: white;
overflow: hidden;
cursor: pointer;
transition: all 0.6s;
}
.login_form button:hover{
background-color: rgba(41, 124, 73, 0.5);
}