Jump to content

Recommended Posts

Posted

I'm trying to learn how to randomize a background image on one of my websites, but I have the image link in my external style sheet like this:

 

#branding{

display:block;

position:absolute;

background-image:url(/body/header.png);

background-repeat: no-repeat;

height:483px;

width:960px;

margin-bottom:-7px;

}

 

I figured out how to randomize images on the html page itself like this:

 

header_<?php echo(rand(1,5)); ?>.jpg

 

It works great, and I want to be able to do the same with the bg img in the style sheet. I read it could be done, but I can't figure it out.

 

Thanks for the help

Posted

Just use php to override the #branding css rules right in the page. That is the easiest way.

 

Another thing you could do, is use php to generate the css file on the fly .. that is more involved thought. You could also do this with DOM scripting.

 

Stefan

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...