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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T22:07:13+00:00 2026-06-09T22:07:13+00:00

I am creating my first blog’s template. I want to have inline images like

  • 0

I am creating my first blog’s template.

I want to have inline images like wikipedia have next to its articles’ paragraphs. I have achieved this with the following code:

<div class="photo">
    <img src="image_file.jpg">
</div>
div[class='photo'] {
    margin: 10px;
    float: left;
    clear: left;
}
img {
    max-width: 500px;
    min-width: 150px;
    margin: 8px;
}

All works fine up to this point. However, I also want to put a caption below the image file so I introduce a

Caption

right after the

<div class="photo">
    <img src="image_file.jpg">
    <p>Caption for the image file which might be long</p>
</div>

Unfortunately, this <p> makes this photo div expand larger than the photo itself causing it to look funny. I would like its max-width to be as large as the photo and go to the 2nd or 3rd line if the text is large.

How can I achieve this? I tried width: auto; display: block;, putting <p> in another div but it fails.

Thank you for your kind help.

PS. I know I can fix the issue once the page is loaded via JS but I would love to learn to solve it the right CSS way. Thanks!

  • 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-06-09T22:07:14+00:00Added an answer on June 9, 2026 at 10:07 pm

    Try this – DEMO

    HTML

    <div class="photo">
        <img src="image_file.jpg">
        <p>Caption for the image file which might be long</p>
    </div>
    

    CSS

    div.photo {
        margin: 10px;
        float: left;
        clear: left;
        position: relative;
        background: honeydew;
    }
    
    div.photo img {
        max-width: 500px;
        min-width: 150px;
        margin: 8px;
    }
    
    
    div.photo p {
        position: absolute;
        bottom: 12px;
        left: 10px;
        right: 8px;
        background: rgba(0, 0, 0, .4);
        color: #fff;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating my own website and blog and I want for first time
I am creating my first wordpress plugin. one of the questions i have is
I'm creating my first application and I have a window consisting of multiple subclasses
I am creating my first (!) database, and I have run into an issue
I am creating my first serious project in PHP and I want to make
I'm in the process of creating a blog for somebody. They want to pull
For the first time I'm creating a quite complex Rails app. I'd like to
I have created a simple bean using this example from Per http://per.lausten.dk/blog/2012/02/creating-your-first-managed-bean-for-xpages.html And I
I have a blog page on the site I'm creating (php/mysql). I generate blog
First attempt at a RoR project and following http://guides.rubyonrails.org/getting_started.html#creating-the-blog-application . I've got the Welcome

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.