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?
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
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
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.
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.