**每天一个小案例:
第一天 (html+css)
登录表单玻璃特效
**
HTML部分
<div class="container">
<form action="#" class="login-form">
<h2>登录</h2>
<input type="text" name="uaername" placeholder="用户名">
<input type="password" name="password" placeholder="密码">
<button type="button">登录</button>
</form>
</div>
CSS部分
<style>
* {
padding: 0;
margin: 0;
}
.container {
width: 100vw;
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
background: url(./img/bgc2.jpg) fixed no-repeat;
block-size: cover;
}
.login-form {
width: 240px;
height: 220px;
display: flex;
padding: 40px;
text-align: center;
position: relative;
flex-direction: column;
background: inherit;
/* 继承父级背景图值,随着图片背景变化 */
z-index: 100;
border-radius: 18px;
overflow: hidden;
}
.login-form::before {
content: "";
width: calc(100% + 20px);
height: calc(100% + 20px);
background: inherit;
box-shadow: inset 0 0 0 200px rgba(255, 255, 255, 0.25);
position: absolute;
top: -10px;
left: -10px;
z-index: -1;
filter: blur(6px);
overflow: hidden;
}
.login-form h2 {
font-size: 18px;
font-weight: 400;
color: #000;
}
.login-form input,
.login-form button {
margin: 6px 0;
height: 36px;
border: none;
background-color: rgba(255, 255, 255, 0.3);
padding: 0 14px;
color: #000;
outline: none;
}
.login-form input::placeholder {
color: gray;
}
.login-form button {
margin-top: 24px;
color: #fff;
background-color: rgba(80, 80, 80, 0.4);
cursor: pointer;
overflow: hidden;
position: relative;
transition: 0.4s;
}
.login-form button:hover {
background-color: rgba(80, 80, 80, 0.8);
}
/* 按钮特效 */
.login-form button::before,
.login-form button::after {
content: "";
display: block;
width: 60px;
height: 100%;
background: rgba(179, 255, 210, 0.3);
opacity: 0.5;
position: absolute;
left: 0px;
top: 0;
transform: skewX(-15deg);
filter: blur(30px);
overflow: hidden;
transform: translateX(-100px);
}
.login-form button::after {
width: 40px;
background: rgba(94, 203, 223, 0.836);
left: 60px;
filter: blur(5px);
opacity: 0;
}
.login-form button:hover:before {
transition: 1s;
transform: translateX(320px);
opacity: 0.7;
}
.login-form button:hover::after {
transition: 1s;
transform: translateX(320px);
opacity: 1;
}
</style>