Results 1 to 5 of 5

Thread: How to display random image in CSS ?

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

  2. #2
    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

  3. #3
    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

  4. #4
    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.

  5. #5
    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.

Similar Threads

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

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,932,807.14642 seconds with 16 queries