Skip to content

Instantly share code, notes, and snippets.

@cierzniak
Last active November 11, 2022 11:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cierzniak/ba5be6e0b5338870de6541616e74ead9 to your computer and use it in GitHub Desktop.
Save cierzniak/ba5be6e0b5338870de6541616e74ead9 to your computer and use it in GitHub Desktop.
Rainbow button
<button class="btn">Test</button>
<!-- Partially based on https://web.dev/speedy-css-tip-animated-gradient-text/ -->
.btn {
cursor: pointer;
display: inline-block;
margin-bottom: 1rem;
font-size: 1.1rem;
height: 2.8rem;
letter-spacing: 0.1rem;
line-height: 2.8rem;
padding: 0px 1.8rem;
text-align: center;
text-decoration: none;
white-space: nowrap;
position: relative;
z-index: 0;
color: rgb(255, 255, 255);
border-color: transparent;
}
.btn:active {
color: rgb(0, 0, 0);
}
.btn::before {
content: "";
position: absolute;
top: -2px;
left: -2px;
z-index: -1;
filter: blur(5px);
width: calc(100% + 4px);
height: calc(100% + 4px);
opacity: 0;
background: linear-gradient(45deg,
rgb(255, 0, 0),
rgb(255, 115, 0),
rgb(255, 251, 0),
rgb(72, 255, 0),
rgb(0, 255, 213),
rgb(0, 43, 255),
rgb(122, 0, 255),
rgb(255, 0, 200),
rgb(255, 0, 0)
) 0% 0% / 400%;
animation: 2s linear 0s infinite normal none running move-background;
transition: opacity 0.3s ease-in-out 0s;
}
.btn:hover::before {
opacity: 1;
}
.btn::after {
z-index: -1;
content: "";
position: absolute;
width: 100%;
height: 100%;
background: rgb(17, 17, 17);
left: 0px;
top: 0px;
}
.btn:active::after {
background: transparent;
}
@keyframes move-background {
to {
background-position: 400% 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment