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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T14:03:19+00:00 2026-05-11T14:03:19+00:00

I am essentially trying to create a version of the figure element (upcoming in

  • 0

I am essentially trying to create a version of the ‘figure’ element (upcoming in HTML5), whereby I have an image with a short description below it.

However, I want to limit the width of this entire element to that of the image, so the text isn’t wider than the image (wrapping to multiple lines if necessary).

Basic HTML:

<div class='figure'> <img src='...' alt='...' width='...' height='...' /><br /> A description for the image </div> 

I’m well-versed with CSS but I can’t think of any pure CSS solution, without adding a style='width:100px' to the div to match the image width.

Update: After a bit of searching and thinking, the best method seems to be using an inline width on the div. I will keep the width attribute on the image, in case I wish the div to be a bit wider than the image (for example to accomodate a longer caption).

This approach also means I could have two images side-by-side with a caption below. If I have a set of images the same size, I can of course add an extra style to each div.

Thanks to everyone who answered!

  • 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. 2026-05-11T14:03:20+00:00Added an answer on May 11, 2026 at 2:03 pm

    Stylesheet

    div.figure img, div.figure div.caption {     width: 100%; } div.figure div {     overflow: hidden;     white-space: nowrap; } 

    note: to enable wrapping just remove that last css line

    HTML

    <div class='figure' style='width:150px;'>     <img src='logo.png' alt='logo' />     <div class='caption'>A description for the image</div> </div> 

    I’ve checked it in Chrome, Firefox and IE7 and it looks good in all three. I realise this has the width on the div and not the img, but at least you only need to set the width in one place. Short of using css-expressions (IE only) I can’t see a way of setting the outer divs width to the width of the first child element.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am essentially trying to create a Button with an image background and border
I am trying to create a Deep Zoom based multiscale image that essentially has
Alright so what I am trying to do is essentially create a program that,
I have the following code: Tag.find_all_by_company_id(4).each.collect{|tag| tag.name }.join(,) (Essentially I'm trying to build a
I'm trying to build a Hibernate layer for a database schema I have essentially
I'm getting an exception when the GetProducts() method is called below. I'm essentially trying
I'm trying to create a particular effect - where essentially various elements move around
Currently I'm trying to create some coding short cuts for our website. Right now
Essentially I'm trying to create the HTML/CSS for an auto-complete. I want it to
What I'm essentially trying to do is to create a 2D array but one

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.