Jump to content

Recommended Posts

I have several images in a directory, which I would like to output(in an organized way) to the page. I've tried reading all the directory contents, and loading their names into an array to display the images using HTML, but I can't for the life of me figure out how to then position the pictures correctly in CSS.

 

Here's the code:

 

<?php
$dirLoc = 'myWebsite/galleryPics';
$handle = opendir($dirLoc);


while($readDir = readdir($handle)){
if($readDir != '.' && $readDir != '..'){
$pic[] = $readDir;
}
}


foreach($pic as $k){
echo "<div class = \"picsDiv\">";
echo "<img src = \"$dirLoc/$k\" height = \"100px\" width = \"100px\"/></div>";
}
?>


<html>
<head>
<style type = "text/css">

.picsDiv {width:150px;
 height:150px;
 border:1px solid red;
 background-color:grey;}

img {position:relative;
 top:50%;
 left:50%;
 margin-top:-50px;
 margin-left:-50px;}
</style>
</head>
</html>

 

Thank you in advance for any feedback.

What is "correctly" supposed to be? How does it look now and how do you want it to look?

 

At the moment the images are positioned in a single, straight, vertical column, with no spaces in between them. I'd like them, however, to run left to right, skipping to the next line once there's no more space, with some space separating them; like a typical grid layout.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.