Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8527963
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T08:41:46+00:00 2026-06-11T08:41:46+00:00

I have an HTML page with 5 images (48px × 48px each) on it.

  • 0

I have an HTML page with 5 images (48px × 48px each) on it. I want to appear the images at random locations on the webpage everytime the page is loaded.

I don’t know how to implement this, I just know I’m going to need CSS and JavaScript (for randomization) for this. Any ideas or suggesions?

Here is sample HTML code:

  <a href="http://twitter.com/"><img alt="Twitter" src="/images/twitter-48.png" /></a>
  <a href="http://facebook.com/><img alt="Facebook" src="/images/facebook-48.png" /></a>
  <a href="https://plus.google.com/"><img alt="Google Plus" src="/images/plus-48.png" /></a>
  <a href="https://github.com/"><img alt="GitHub" src="/images/github-48.png" /></a>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T08:41:47+00:00Added an answer on June 11, 2026 at 8:41 am

    Lets assume that you already have the images hardcoded on to your html document. What you would need to do (if you want to accomplish this with PHP) is add a style attribute to each element. In your case, your images are held within <a> tags, so you’ll want to position the <a> tag randomly and not the images…

    function generateRandomPositions(){
    
      // define maximum and minimum 'top' values
      $maxTop = 1000;
      $minTop = 0;
    
      // define maximum and minimum 'left' values    
      $maxLeft = 1000;
      $minLeft = 0; 
    
    
      $styleProperties = array(
        'position:absolute',
        'top:'.rand($minTop,$maxTop) . 'px',
        'left:'.rand($minLeft,$maxLeft) . 'px'
      );
    
      return ' style="'.implode(';',$styleProperties).'" ';
    }
    

    The function will return a string similar to this –

    style="position:absolute;top:10px; left:45px;"
    

    Now all you have to do is call this function for each image on your page –

    <a <?php echo generateRandomPositions();?> ><img src="...
    <a <?php echo generateRandomPositions();?> ><img src="...
    <a <?php echo generateRandomPositions();?> ><img src="...
    <a <?php echo generateRandomPositions();?> ><img src="...
    

    Your <a> tags will now contain random CSS positioning parameters and their images will move with them.

    As I’m sure you can see, this method of using PHP to generate inline CSS properties is kind of a backwards way to do this. JavaScript would probably be the best way to get what you are looking for and there are other answers that cover it. You could initially hide your elements with CSS and then display them with the JavaScript after you have set the random positioning.


    References –

    • rand()
    • implode()
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a HTML page with three sets of images on. I want each
I have an HTML page where I want to refresh a lot of images
I have dynamically created images on my index.html page. I want the user to
I have an html page full of images. Currently, each image is a link
I don't know how to parse HTML page content in iPhone SDK? I have
I have a page in HTML(index.html), and a folders named images, css, js that
I have an HTML page that contains some filenames that i want to download
I have an html page loaded into a PHP variable and am using str_replace
Hy I have a html page in witch I want to open a php
I have a html page, on this page there are some images, when the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.