边框动画
项目来源于抖音博主 - 前端斌少
预览
此演示仅在桌面端浏览器中可用
html
html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<link rel="stylesheet" href="./style.css" />
</head>
<body>
<div class="wrap">
<div class="box">
<h1>Border Animation</h1>
<span class="border-top"></span>
<span class="border-right"></span>
<span class="border-bottom"></span>
<span class="border-left"></span>
</div>
</div>
</body>
</html>css
css
.wrap {
width: 400px;
height: 200px;
margin: 100px auto;
}
.box {
position: relative;
padding: 20px 35px;
overflow: hidden;
border-radius: 5px;
}
.border-top {
position: absolute;
top: 0;
right: 0;
width: 100%;
height: 3px;
background: linear-gradient(to right, #ec107e, #fcc23f);
animation: animate-border-top 2s linear infinite;
}
h1 {
text-align: center;
}
@keyframes animate-border-top {
0% {
transform: translateX(-100%);
}
100% {
transform: translateX(100%);
}
}
.border-right {
position: absolute;
top: 0;
right: 0;
height: 100%;
width: 3px;
opacity: 0;
background: linear-gradient(to bottom, #ec107e, #fcc23f);
animation: animate-border-right 2s linear infinite;
animation-delay: 1s;
}
@keyframes animate-border-right {
0% {
opacity: 0;
transform: translateY(-100%);
}
0.1% {
opacity: 1;
}
100% {
opacity: 1;
transform: translateY(100%);
}
}
.border-bottom {
position: absolute;
bottom: 0;
left: 0;
width: 100%;
height: 3px;
background: linear-gradient(to left, #ec107e, #fcc23f);
animation: animate-border-bottom 2s linear infinite;
}
@keyframes animate-border-bottom {
0% {
transform: translateX(100%);
}
100% {
transform: translateX(-100%);
}
}
.border-left {
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 3px;
opacity: 0;
background: linear-gradient(to top, #ec107e, #fcc23f);
animation: animate-border-left 2s linear infinite;
animation-delay: 1s;
}
@keyframes animate-border-left {
0% {
opacity: 0;
transform: translateY(100%);
}
0.1% {
opacity: 1;
}
100% {
opacity: 1;
transform: translateY(-100%);
}
}