This content originally appeared on CSS-Tricks and was authored by Chris Coyier
This little trick for gradient borders is super useful:
.border-gradient {
border: 5px solid;
border-image-slice: 1;
border-image-source: linear-gradient(to left, #743ad5, #d53a9d);
}
Here’s some basic demos from our article on the subject. Sephanie Eckles was sharing around the idea with more detail. Bramus Van Damme saw that and stretched it a bit by adding, then animating an angle to the gradient. Like:
div {
--angle: 0deg;
/* … */
border-image: linear-gradient(var(--angle), green, yellow) 1;
animation: 10s rotate linear infinite;
}
@keyframes rotate {
to {
--angle: 360deg;
}
}
But wait! That’s not actually going to animate as-is. The browser doesn’t know that 360deg
is an actual angle value, and not just some random string. If it did know it was an angle value, it could animate it. So, tell it:
@property --angle {
syntax: '<angle>';
initial-value: 0deg;
inherits: false;
}
See Bramus’ article for the demos there. Bonafide CSS trick. I can’t wait for more support for @property
(Chrome only, as I write), because it really unlocks some cool CSS trickery. Animating numbers visually, for example.
Direct Link to Article — Permalink
The post Animating a CSS Gradient Border appeared first on CSS-Tricks.
You can support CSS-Tricks by being an MVP Supporter.
This content originally appeared on CSS-Tricks and was authored by Chris Coyier

Chris Coyier | Sciencx (2021-02-08T15:24:23+00:00) Animating a CSS Gradient Border. Retrieved from https://www.scien.cx/2021/02/08/animating-a-css-gradient-border/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.