Animate Borders

by Sebastian Kay

HTML

<div class="card">
  <h1>Animate Borders</h1>
  <p>
    Lorem ipsum dolor sit amet, consectetur adipisicing elit. Atque ad
    exercitationem voluptatem ullam et, natus impedit quae veniam optio a
    doloremque officiis beatae, itaque nesciunt nostrum quasi molestiae
    laudantium dolor asperiores soluta sint sed ratione cupiditate. Laudantium
    earum reiciendis enim.
  </p>
  <script src="https://unpkg.com/@dotlottie/player-component@latest/dist/dotlottie-player.mjs" type="module"></script> 
  <dotlottie-player src="https://lottie.host/1419a6d2-9454-46bc-af8d-1caa7ecad149/7iAPFrXfc4.json" background="transparent" speed="1" style="width: 100%; height: 100%;" loop autoplay></dotlottie-player>
</div>

CSS

* {
  margin: 0;
  padding: 0;
}
html {
  font-family: Poppins;
  color: #f0f0f0;
}
body {
  min-height: 100vh;
  background: #0b0d15;
  color: #a2a5b3;
  align-content: center;
}
h1 {
  color: white;
}
.card {
  margin: 0 auto;
  padding: 2em;
  width: 300px;
  background: #1c1f2b;
  text-align: center;
  border-radius: 10px;
  position: relative;
}

@property --angle {
  syntax: "<angle>";
  initial-value: 0deg;
  inherits: false;
}

.card::after,
.card::before {
  content: "";
  position: absolute;
  opacity: 0;
  transition: opacity 0.4s linear;
  height: 100%;
  width: 100%;
  background-image: conic-gradient(from var(--angle), #ff4545, #00ff99, #006aff, #ff0095, #ff4545);
  top: 50%;
  left: 50%;
  translate: -50% -50%;
  z-index: -1;
  padding: 3px;
  border-radius: 10px;
  animation: 3s spin linear infinite;
}
.card::before {
  filter: blur(1.5rem);
  opacity: 0;
}

.card:hover::after {
  opacity: 1;
}
.card:hover::before {
  opacity: 0.5;
}

@keyframes spin {
  from {
    --angle: 0deg;
  }
  to {
    --angle: 360deg;
  }
}