Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Antimation to change the color of div border every second with CSS

Tags:

html

css

I want to change the color of a div border, so that the color changes every second to another color.

I don't 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>
like image 654
Bernard Bierbuik Avatar asked Jan 06 '23 00:01

Bernard Bierbuik


1 Answers

If you know the sequence of the colors or simply you don't care, you can use a CSS rule called @Keyframes animation, it is compatible with most of the modern browsers and you can do a lot of tricky things like this:

.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>

Working jdfiddle demo.

like image 84
Troyer Avatar answered Jan 10 '23 20:01

Troyer