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 6114389
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:58:08+00:00 2026-05-23T14:58:08+00:00

I am tried to use PHP to make DIV random positions. Here is my

  • 0

I am tried to use PHP to make DIV random positions. Here is my code.

<?php
function DIV1()
{
    $choose = array("left", "right");
    $rand_keys = array_rand($choose, 1);
    echo "<div class=position1 style=\"float:left;width:100px;height:100px;background-color:#00f;float:".$choose[$rand_keys].";border:1px solid #000;\"></div>";
}
function DIV2()
{
    $choose = array("left", "right");
    $rand_keys = array_rand($choose, 1);
    echo "<div class=position2 style=\"float:left;width:100px;height:200px;background-color:#f00;float:".$choose[$rand_keys].";border:1px solid #000;\"></div>";
}
function DIV3()
{
    $choose = array("left", "right");
    $rand_keys = array_rand($choose, 1);
    echo "<div class=position3 style=\"float:left;width:200px;height:100px;background-color:#ff0;float:".$choose[$rand_keys].";border:1px solid #000;\"></div>";
}

echo '<div id="display" style="width:1016px;height:1016px;background-color:#333;">';
    $count = Math.floor(rand()*25) +15;
    for ($i=0; $i<$count; $i++)
    {
        echo DIV1();
        echo DIV2();
        echo DIV3();
    }

echo '</div>';
?>

My code can mixed divs position. But I have 2 questions.

  1. How to control 15 pieces 100*100, 10 pieces 100*200, 5 pieces 200*100 divs mixed random display?

  2. How to control the white space part? I want show all the divs in the display zone. width:1016px;height:1016px;, do not out of the div#display.

  • 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-05-23T14:58:09+00:00Added an answer on May 23, 2026 at 2:58 pm
    $sizes = array();
    
    for ($i = 0; $i < 15; $i++) {
        array_push($sizes, $array(100,100));
    }
    for ($i = 0; $i < 10; $i++) {
        array_push($sizes, $array(100,200));
    }
    for ($i = 0; $i < 5; $i++) {
        array_push($sizes, $array(200,100));
    }
    
    for ($i = 0; $i < 30; $i++) {
       // Use array_rand() to pick out a random entry from $sizes and echo the div
    }
    

    About it not being out of the boundaries, just have it get a random top and left within those boundaries taking into account the width and height of the div.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Firstly poor of my mathematica. I tried to use php to make a number
I tried to use the Http Authentication Digest Scheme with my php (apache module)
I've got a problem with a CKEditor plugin. I need PHP code to make
I have tried to use templates to be able to make a multilingual web
right now , I use jQUery(document).ready to inject javascript into a div. All is
I want to make a php ajax post.(post value without refresh the page) here
I want to make a php ajax post.(post value without refresh the page) here
I was wondering what is the right way to use PHP in an Object
I am retro-fitting an application to make use of a PHP HTTP proxy (for
I'm currently developing a website that will make use of PHP scripts and I'd

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.