Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 16-01-2009
Member
 
Join Date: Nov 2008
Posts: 1,221
How to display random image in CSS ?

I am trying to edit and change a theme applied to a coppermine gallery. I have some basic HTML knowledge, but that's all. So, I found the code of my image called as "headerbg.gif".

HTML Code:
.header{ 
background: url(images/headerbg.gif) no-repeat; 
width: 760px; 
height: 143px; 
float: left; 
}
I want to replace that code so that the image is random ... I found the following code:

PHP Code:
<? 
$imgs 
= array("image1.gif""image2.gif""image3.gif"); 
srand ((double)microtime()*1000000); 
shuffle($imgs); 
echo 
'< img src = "imagedirectory/' $imgs[0] . '" border = "0" alt="" />'
?>
The problem is that PHP, and this stylesheet is difficult to eat this code ...

Someone have an idea to display a random image? Or even change the image every day?
Reply With Quote
  #2  
Old 16-01-2009
XSI XSI is offline
Member
 
Join Date: May 2008
Posts: 271
Re: How to display random image in CSS ?

We can't make dynamic CSS ... In your case, you can make CSS to set the format for this image which will appear against it from the PHP
Reply With Quote
  #3  
Old 16-01-2009
Member
 
Join Date: Feb 2008
Posts: 194
Re: How to display random image in CSS ?

overload the style of your header in your php page directly in the tag. So you will be benefited from the dynamic side of my php random play on your style

PHP Code:
<? 
$imgs 
= array("image1.gif""image2.gif""image3.gif"); 
srand ((double)microtime()*1000000); 
shuffle($imgs); 
?> 

... 
<div style="background: url(<?echo 'imagedirectory/' $imgs[0]; ?>) no-repeat"> 
...
it is how object (div, span, ...) is assigned the style .header for overloading
Reply With Quote
  #4  
Old 16-01-2009
Member
 
Join Date: Nov 2008
Posts: 1,221
Re: How to display random image in CSS ?

Well, I consider that, for all you said is to change the header of my coppermine gallery ... The image is placed by the CSS, hence my question.
Reply With Quote
  #5  
Old 16-01-2009
Member
 
Join Date: Feb 2008
Posts: 194
Re: How to display random image in CSS ?

In fact rather than placing the image via css, it must be placed directly in the php page via a style always (a local css)

I have given the code above which you want to put in your .php page that contains the words "class = header" and put in this tag

PHP Code:
class = "header" style="background: url (<?echo 'imagedirectory/' $imgs[0]; ?>) no-repeat">
You wrote this script a little further up the page that makes the images shuffle on the table.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "How to display random image in CSS ?"
Thread Thread Starter Forum Replies Last Post
Getting random white Pixel inside Black image on Mozilla Firefox 6.0 gANdHAaIt Technology & Internet 6 25-08-2011 10:30 AM
Random Text Display Using JavaScript Beter 2 Burn Out Software Development 4 03-02-2010 05:52 AM
Image Display In Java Amaresh Software Development 5 30-01-2010 09:20 AM
PHP Random image 3 images in a row fastrod Software Development 4 09-03-2009 01:40 PM
How to display image from the web in ACCESS Janet J Software Development 2 04-02-2009 06:45 PM


All times are GMT +5.5. The time now is 01:54 PM.