Welcome to WebmasterWorld Guest from

Forum Moderators: not2easy

Message Too Old, No Replies

Rotating Image

8:03 pm on May 14, 2010 (gmt 0)

Junior Member

10+ Year Member

joined:Feb 10, 2006
posts: 64
votes: 0

I have a web page that has a small table to the left of the main content. The background of that area is an image that is defined in the css file.

Is it possible to place a script in there for the image to randomly rotate to a new one with still using the css?
8:29 am on May 16, 2010 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Mar 4, 2004
votes: 1

You can use php, style.php :

header("Content-Type: text/css");

$rand_num = mt_rand(1, 4);
.randimage {
background-image: url('randimage<?php echo $rand_num ?>.gif');

The first line is the most important because it will send the right header to the browser. The variable $rand_num is assigned a number between 1 to 4.

You'll have four images:
randimage2.gif ... etc