HTML5+CSS3做一組毛玻璃炫光按鈕,主要用到投影+模糊濾鏡+CSS動(dòng)畫涩盾,搞定十气,看效果吧。
效果:
源碼:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no">
<title>毛玻璃炫光按鈕</title>
<link rel="stylesheet" href="../css/32.css">
</head>
<body>
<div class="container">
<div class="btn"><a href="#">我要點(diǎn)贊</a></div>
<div class="btn"><a href="#">我要關(guān)注</a></div>
<div class="btn"><a href="#">我要評論</a></div>
</div>
</body>
</html>
*{
/* 初始化 取消頁面元素的內(nèi)外邊距 */
margin: 0;
padding: 0;
/* 這個(gè)是告訴瀏覽器:你想要設(shè)置的邊框和內(nèi)邊距的值是包含在總寬高內(nèi)的 */
box-sizing: border-box;
}
body{
/* 彈性布局 水平春霍、垂直居中 */
display: flex;
justify-content: center;
align-items: center;
/* 100%窗口高度 */
height: 100vh;
position: relative;
background: linear-gradient(200deg,#2b5876,#033557);
}
.container{
/* 彈性布局 */
display: flex;
/* 允許換行 */
flex-wrap: wrap;
/* 將元素靠邊對齊 */
justify-content: space-around;
}
.container .btn{
/* 相對定位 */
position: relative;
width: 200px;
height: 60px;
margin: 30px;
}
.container .btn a{
/* 絕對定位 */
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
background: rgba(255,255,255,0.05);
/* 陰影 */
box-shadow: 0 15px 35px rgba(0,0,0,0.2);
border-top: 1px solid rgba(255,255,255,0.1);
border-bottom: 1px solid rgba(255,255,255,0.1);
border-radius: 30px;
color: #fff;
z-index: 1;
font-weight: 400;
letter-spacing: 1px;
text-align: center;
text-decoration: none;
/* 溢出隱藏 */
overflow: hidden;
transition: 0.5s;
/* 背景模糊 */
backdrop-filter: blur(15px);
}
.container .btn:hover a{
/* 字間距 */
letter-spacing: 5px;
}
/* 掃光效果 */
.container .btn a::before{
content: "";
/* 絕對定位 */
position: absolute;
top: 0;
left: 0;
width: 50%;
height: 100%;
/* 漸變背景 透明到白色 */
background: linear-gradient(to right,transparent,rgba(255,255,255,0.15));
/* 沿X軸傾斜45度,向右平移0像素 */
transform: skewX(45deg) translateX(0);
/* 動(dòng)畫過渡 */
transition: 0.5s;
}
.container .btn:hover a::before{
/* 沿X軸傾斜45度,向右平移200% */
transform: skewX(45deg) translateX(200%);
}
/* 按鈕上下兩個(gè)發(fā)光層 */
.container .btn::before,
.container .btn::after{
content: "";
position: absolute;
left: 50%;
transform: translateX(-50%);
width: 40px;
height: 10px;
/* 設(shè)置背景顏色,--c是自定義屬性(顏色),通過var函數(shù)調(diào)用 */
background: var(--c);
/* 圓角 */
border-radius: 5px;
/* 設(shè)置陰影 */
box-shadow:
0 0 5px var(--c),
0 0 15px var(--c),
0 0 30px var(--c),
0 0 60px var(--c)
;
transition: 0.5s;
}
.container .btn:hover::before,
.container .btn:hover::after{
height: 50%;
width: 80%;
border-radius: 15px;
/* 動(dòng)畫延遲 */
transition-delay: 0.3s;
}
.container .btn::before{
bottom: -5px;
}
.container .btn:hover::before{
bottom: 0;
}
.container .btn::after{
top: -5px;
}
.container .btn:hover::after{
top: 0;
}
/* 分別設(shè)置自定義屬性--c */
.container .btn:nth-child(1)::before,
.container .btn:nth-child(1)::after{
--c: #12c2e9;
}
.container .btn:nth-child(2)::before,
.container .btn:nth-child(2)::after{
--c: #c471ed;
}
.container .btn:nth-child(3)::before,
.container .btn:nth-child(3)::after{
--c: #f64f59;
}