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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:35:14+00:00 2026-05-29T10:35:14+00:00

Evening front end wizards. I’m trying to do something that should be quite simple:

  • 0

Evening front end wizards. I’m trying to do something that should be quite simple: I want to have images floated right or left in my body content, with a caption below each image. To try and achieve this I’m floating a div with the image inside it, followed by a span with a caption below. I’ve given the image max-width 100% so my layout is responsive.

Is there any way using just CSS and HTML that I can constrain the width of the containing div to the width of the image inside it? I’m finding that the span below pushes out the width of the div, whether it’s display:inline-block or not. I’d like the span to always be the same width as the image, so the text wraps in line with the image’s right edge.

I’d like to be able to use images of varying widths, so setting a max-width on the div doesn’t really do the trick. I could do it easily enough with JQuery, but that would be cheating.

Any suggestions gratefully received! You can see what I’m talking about at http://jsfiddle.net/andfinally/yBHjK/

  • 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-29T10:35:15+00:00Added an answer on May 29, 2026 at 10:35 am

    It sounds like you want the containing div to expand it’s width only for img elements and not span elements. Is that correct?

    There is no pure CSS solution for this, JavaScript is the best way to achieve what you’re after.

    Two similar questions:

    • CSS: Force text to wrap (OR defining element width by only one of its children)

    • Limit text to the width of sibling image / auto width in CSS

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

Sidebar

Related Questions

Good evening, In my app that I'm currently developing, I have a class that
Good evening, i need to know how can i have one .h file that
Good evening I have a JTable that I built with a TableModel how to
Evening all. I have the following code that I need looking into - basically
We have a very large number of SSIS jobs that are scheduled every evening/early
Evening all! I have half a script that I need to change the CSS
Good evening all, I'm trying to write a method that creates and returns a
Good evening, here is what I am trying to achieve, I currently have a
Evening folks, I have a complex MySQL COUNT query I am trying to perform
Good Evening All, I have a textbox that needs to accept 14 digits plus

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.