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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:52:31+00:00 2026-05-25T00:52:31+00:00

The situation is I have an img and I want a pop-over caption-box whose

  • 0

The situation is I have an img and I want a pop-over caption-box whose width is the width of the img. I can’t add the caption as a child of the img, because img tags don’t take children. Hence my idea was to have something like this:

<div>
   <img/>
   <div>
      ...caption...
   <div>
</div>

The problem is the outer divs expand to fill the width of their parent, as block elements do, and hence the caption-div becomes equally wide, and I get something that looks like this:

enter image description here

Where the outer div becomes the width of the page, the caption follows the width of the outer div and thus sticks out of the image.

I do not want to manually set the width of the outer div, because I am using this sub-template for images of all shapes and sizes all over the site. Is there anyway to make the outer-div hug the image, rather than fill his parent?

  • 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-05-25T00:52:32+00:00Added an answer on May 25, 2026 at 12:52 am

    I do not want to manually set the width of the outer div, because I am
    using this sub-template for images of all shapes and sizes all over
    the site. Is there anyway to make the outer-div hug the image, rather
    than fill his parent?

    You need display: inline-block combined with text-align: center.

    See: http://jsfiddle.net/thirtydot/V3XyK/

    HTML:

    <div class="imageContainer">
        <div>
            <img src=".." />
            <span>...caption...</span>
        </div>
    </div>
    

    CSS:

    .imageContainer {
        text-align: center;
    }
    .imageContainer img {
        display: block;
    }
    .imageContainer div {
        position: relative;
        display: inline-block;
        /* if you need ie6/7 support */
        *display: inline;
        zoom: 1;
    }
    .imageContainer span {
        position: absolute;
        left: 0;
        bottom: 0;
        width: 100%;
        background: #000;
        background: rgba(0,0,0,.5);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Situation: I have some persons with certain skills and they can/might belong to more
I have a problem because i can´t work my images or css when my
I have the following situation, I have an html file with image tags about
I have a situation I don´t know how to model correctly. I want every
I have url and img tag like these (files can have gif, png or
I have a situation where I want to return an animated gif from an
I have a situation where I have one div of fixed width, containing an
I have an image of a map, and I want to add the address
I have following situation - Have a MongoService class, which reads host, port, database
Pseudo-situation: have a class (let's say BackgroundMagic ), and it has Start() and Stop()

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.