-2

I want to know how can I change the background color after couple of seconds in css?

For example I want 3 colors: blue, red, green. After each 3 seconds the background color is changing.

Does anyone has any idea?

This is my code. But I can change only 2 colors and is not looping

p {
    display: inline;
    animation: background-fade 3s forwards;
    -webkit-animation: background-fade 3s forwards;
    -moz-animation: background-fade 3s forwards;
}

@-webkit-keyframes background-fade {
    100% {
        background:#c92884;
    }
}

JSFidlle http://jsfiddle.net/326mJ/7/

Flap Jack
  • 97
  • 1
  • 14

1 Answers1

4

try like this: Demo

body{

animation: background-fade 10s infinite;    
}

@keyframes background-fade {
    0% {
        background:red;
    }
    50% {
        background:blue;
    }
    100% {
        background:green;
    }
}

You need to use infinite instead of forwards for looping

G.L.P
  • 7,119
  • 5
  • 25
  • 41