Animated button border
by kthornbloom
HTML
<a href="#" class="outline">
<div>BUTTON</div>
</a>
CSS
body {
background: #000;
font-family: sans-serif;
}
.outline {
display: inline-block;
color: #fff;
text-decoration: none;
position: relative;
padding: 1px;
overflow: hidden;
border-radius: 50px;
> div {
background: linear-gradient(40deg, #000, #222);
border-radius: 50px;
padding: 1rem 4rem;
font-size: 14px;
}
}
.outline::before {
content:'';
position: absolute;
width: 100%;
aspect-ratio: 1/1;
display: block;
left: 0;
top: 50%;
transform: translateY(-50%);
background: conic-gradient(#ffffff20 160deg, #ffffff, #ffffff20 200deg);
z-index: -1;
animation: spin 5s infinite linear;
}
@keyframes spin {
0% {
transform: translateY(-50%) rotate(0deg);
}
25% {
transform: translateY(-50%) rotate(90deg);
animation-timing-function: ease-out;
}
50% {
transform: translateY(-50%) rotate(180deg);
animation-timing-function: ease-in;
}
75% {
transform: translateY(-50%) rotate(270deg);
animation-timing-function: ease-out;
}
100% {
transform: translateY(-50%) rotate(360deg);
animation-timing-function: ease-in;
}
}