Change div border color every second with CSS

I want to change the color of the div frame so that the color changes every second to a different color.

I do not know how to do this, any help? This is my code.

/* Style the links inside the list items */
ul.topnav li a {
  display: inline-block;
  border-left: 3px solid;
  border-left-color: #FF0000;
  border-top-color: #F5FF00;
  border-top-style: double;
  border-bottom: 3px solid;
  border-bottom-color: #FF0000;
  border-right-style: double;
  border-right-color: #F5FF00;
  border-radius: 40px;
  color: #f2f2f2;
  text-align: center;
  padding: 14px 16px;
  text-decoration: none;
  transition: 0.3s;
  font-size: 17px;
}
<header>
  <ul class="topnav" id="drop">
    <li><a class="selected" href="home.html">Home</a></li>
    <li>
      <a href="project.html">Project</a>
      <ul>
        <li><a href="project.html">Algemeen</a></li>
        <li><a href="test.html">test</a></li>
        <li><a href="test2.html">test2</a></li>
      </ul>
    </li>
    <li><a href="contact.html">Contact</a></li>
    <li class="icon">
      <a href="javascript:void(0);" onclick="myFunction()">&#9776;</a>
    </li>
  </ul>
</header>
Run codeHide result
+4
source share
1 answer

If you know the sequence of colors or you just don’t care, you can use the CSS rule called @ keyframes animation , it is compatible with most modern browsers , and you can do many complex things, such as:

.border-glow {
  border: 1px solid blue;
  animation: 4s infinite glow;
}
@keyframes glow {
  0% {
    border-color: red;
  }
  25% {
    border-color: blue;
  }
  75% {
    border-color: yellow;
  }
  100% {
    border-color: purple;
  }
}
@-webkit-keyframes glow {
  0% {
    border-color: red;
  }
  25% {
    border-color: blue;
  }
  75% {
    border-color: yellow;
  }
  100% {
    border-color: purple;
  }
}
<div class="border-glow">Shiny!</div>
Run codeHide result

Working jdfiddle demo.

+9
source

Source: https://habr.com/ru/post/1662114/


All Articles