Jump to content

HTML - How can I place images side by side without breaking the code?


Gamerz

Recommended Posts

Okay...so here's what I'm trying to accomplish:

----------

[iMAGE ONE GOES HERE...........................]    [iMAGE TWO GOES HERE...........................]            [iMAGE THREE GOES HERE.....]

      [DESCRIPTION HERE VIA BR TAG]                    [DESCRIPTION HERE VIA BR TAG]                                [DESCRIPTION...]

 

 

[iMAGE FOUR GOES HERE...........................]    [iMAGE FIVE GOES HERE...........................]            [iMAGE SIX GOES HERE.....]

      [DESCRIPTION HERE VIA BR TAG]                    [DESCRIPTION HERE VIA BR TAG]                                [DESCRIPTION...]

----------

I've noticed the   thing doesn't work...so I can't exactly use it to space out my images without going to next line.

Basically, I want around around 3-6 images with text per row...how would I construct that?

<div class="image">
  <img src="path/to/img.jpg" alt="image" />
  <p>caption</p>
</div>
<div class="image">
  <img src="path/to/img.jpg" alt="image" />
  <p>caption</p>
</div>
<div class="image">
  <img src="path/to/img.jpg" alt="image" />
  <p>caption</p>
</div>
<div class="image">
  <img src="path/to/img.jpg" alt="image" />
  <p>caption</p>
</div>
<div class="image">
  <img src="path/to/img.jpg" alt="image" />
  <p>caption</p>
</div>
<div class="image">
  <img src="path/to/img.jpg" alt="image" />
  <p>caption</p>
</div>

 

CSS:

 

div.image
{
  float:left;
  width:__px; // adjust this to the width of your images.
}

 

If you have more than three images showing up on one line, add a right margin to div.image until they space out enough to bump anything above three images down to the next row.

 

Here's my code below...how do I add a width to the container they are in and center it?

 

<html>
<head>
<style type="text/css">
div.image
{
margin-right: 0px;
float:left;
width:100px; // adjust this to the width of your images.
}
</style>
</head>
<body>
<p>
<div class="image">
  <a href="lol.php"><img src="folder_icon.jpg" alt="image" style="border: 0px dashed black;" width="50" height="50"/>
  <p>text</p></a>
</div>
<div class="image">
   <a href="lol.php"> <img src="folder_icon.jpg" alt="image" style="border: 0px dashed black;" width="50" height="50"/>
  <p>text</p></a>
</div>
<div class="image">
  <a href="lol.php">  <img src="folder_icon.jpg" alt="image" style="border: 0px dashed black;" width="50" height="50"/>
  <p>text</p></a>
</div>
<div class="image">
  <a href="lol.php">  <img src="folder_icon.jpg" alt="image" style="border: 0px dashed black;" width="50" height="50"/>
  <p>text</p></a>
</div>
<div class="image">
    <a href="lol.php"><img src="folder_icon.jpg" alt="image" style="border: 0px dashed black;" width="50" height="50"/>
  <p>text</p></a>
</div>
<div class="image">
   <a href="lol.php"> <img src="folder_icon.jpg" alt="image" style="border: 0px dashed black;" width="50" height="50"/>
  <p>text</p></a>
</div>

</p>
</body>
</html>

First, you have your images inside a <p> tag. This is invalid code. You can't have div tags inside <p> tags. Change your p tag to a div tag, and give it an ID. Then target that ID in your CSS and set a width to it. To center it, you can use this:

 

margin:0 auto;

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.