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?

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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;

Link to comment
Share on other sites

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.