Jump to content

I want to put a caption below the image.


Go to solution Solved by vet911,

Recommended Posts

I want to put a caption below the image and have it move in this responsive layout with the image.

Any help would be appreciated.

<style>
/* For small devices (e.g. smartphones) */
img {
  max-width: 100%;
  display: inline-block;
  padding: 0.5%;
}
/* For medium devices (e.g. tablets) */
@media (min-width: 420px) {
  img {
    max-width: 100%;
  }
}
/* For large devices (e.g. desktops) */
@media (min-width: 960px) {
  img {
    max-width: 33%;
  }
}
</style>
<div>
 <img src="images/69dyellow.png"  />
 <img src="images/65silver.png"  />
 <img src="images/64red.png"  />
 <img src="images/66blue.png" />
</div>
Link to comment
https://forums.phpfreaks.com/topic/297839-i-want-to-put-a-caption-below-the-image/
Share on other sites

  • Solution

Okay I took it to heart. I have figured it out. It works fine but the text is a little to far from the image. Not sure how to fix that. I tried using padding but didn't seem to work. Any help?

<style>
.image-holder
	{
  float:left;
  margin:5px;
  text-align: center;
  padding:10px 10px 0px 10px;
  color:#000; 
}

</style>

     <div class="image-holder">
     <img src="images/69astro_red.png" alt="" />
     <p>1969 Astro Red Convertible</p>
     </div>
     <div class="image-holder">
     <img src="images/69my.png" alt="" />
     <p>1969 Daytona Yellow </p>
     </div>
     <div class="image-holder">
     <img src="images/69dyellow.png" alt="" />
     <p>1969 Dark Yellow #W995</p>
     </div>
     <div class="image-holder">
     <img src="images/69red_no_head_1.png" alt="" />
     <p>1969 Red Convertible w/no headrest</p>
     </div>

Your solution is fine, but I just want to point out that in HTML5 there are two new elements for accomplishing this very thing: figure and figcaption. It's not as compatible as just using div and p though, but more semantic.

 

Here is an example: http://jsfiddle.net/tvzvzw97/

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.