[thelist] Conditionals in CSS - php?

Paul Bennett paul at web-business-pack.com
Thu Sep 30 18:51:29 CDT 2004

why not use javascript?

Have a default iamge in your css and overwrite it with document.write 
(fro js enabled browsers)
here's some code I had lying around...

var imagenumber = 5 ;
var randomnumber = Math.random() ;
var rand1 = Math.round( (imagenumber-1) * randomnumber) + 1 ;
images = new Array;
images[1] = "people.jpg";
images[2] = "people_2.jpg";
images[3] = "people_3.jpg";
images[4] = "people_4.jpg";
images[5] = "people_5.jpg";
var image = images[rand1];

document.write('<style type="text/css">');
document.write('background: url("images/' + image +'"); 
background-repeat: no-repeat;');


Paul B

Tom Dell'Aringa wrote:

>I'm wanting to rotate some pictures in the banner of my site. This banner is set by a background
>style in my CSS like so:
>blah { background: #fff url(somepic.jpg); }
>I'm using PHP as my server side scripting. What I want to do is randomize that URL so that it
>grabs one of n photos on pageload.
>Is there some way I can configure my CSS file to execute php code (with .htaccess perhaps?) Or,
>can I actually specify a php file as my style sheet (definitely not ideal - hate to do that
>Looking for any suggestions. Thanks!
>Get Firefox! | http://www.pixelmech.com/

More information about the thelist mailing list