CSS动画 流光按钮
•笔记
27
0
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>css流光按钮</title>
<link rel="stylesheet" type="text/css" href="css/style.css"/>
</head>
<body>
<a href="https://www.13i4.cn/8.html">Button</a>
</body>
</html>
/* 设置内容居中,设置底色 */
body{
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
background-color: #000;
}
/* 按钮基本宽高,背景颜色,水平居中,垂直居中 */
a{
position: relative;
display: inline-block;
width: 200px;
height: 60px;
background-color: skyblue;
color: #fff;
line-height: 60px;
text-align: center;
}
/* 修改为渐变背景,设置渐变背景图的大小,微修圆角 */
a{
text-decoration: none;
background: linear-gradient(90deg,#03a9f4,#f441a5,#ffeb3b,#03a9f4);
background-size: 400%;
border-radius: 10px;
}
/* 设计动画 */
@keyframes animate {
0%{
background-position: 0 0;
}
100%{
background-position: 400% 0;
}
}
/* 使用动画 */
a:hover{
animation: animate 8s linear infinite;
}
/* 准备光影盒子,比原盒子略大 */
a:before{
content: '';
position: absolute;
left: -5px;
top: -5px;
right: -5px;
bottom: -5px;
z-index: -1;
}
/* 设置光影的背景渐变,背景大小和圆角 */
a:before{
background: linear-gradient(90deg,#03a9f4,#f441a5,#ffeb3b,#03a9f4);
background-size: 400px;
border-radius: 10px;
}
/* 默认不显示光影,hover时加模糊度实现光影效果 */
a:before{
opacity: 0;
transition: all 1s;
}
a:hover:before{
filter: blur(20px);
opacity: 1;
}
1.渐变背景,修改背景定位流动
2.blur模糊实现基本光影