Hey, I need some help with CSS. I would like to be able to cycle images through CSS to keep visitors "on their toes" with an everchanging background. I have multiple .jpg backgrounds that I would just like for it to cycle or be random.
A couple methods I can think of using PHP.. 1. Randomly assigning an ID or CLASS to the element that you want to have a different background... $foo = rand(1, 5); <body class="<?php echo 'section-' . $foo; ?>"> And in your CSS body.section-1 { background-image:url(1.jpg) no-repeat; } body.section-2 { background-image:url(2.jpg) no-repeat; } 2. Making your stylesheet PHP itself.. with content-type of text/css, and having an array inside with the images that you need $images = array ('foo.jpg', 'bar.jpg', 'moo.jpg'); div#wrapper { background-image:url( <?php echo array_rand($images); ?> ) } Although you might have some problems getting this PHP stylesheet to cache. 3. Linking to a PHP page that randomly outputs images IN the CSS. background-image:url(foo.php) where foo.php has a content-type of image/jpeg or whatever the randomly generated image's mime type is Although, I have never tried methods #2 and #3 myself.. I would probably recommend the first method since its the easiest.