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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:22:39+00:00 2026-06-12T15:22:39+00:00

Say, a parent div has two child divs, one containing text, the other containing

  • 0

Say, a parent div has two child divs, one containing text, the other containing an image of known (but variable) width & height.

I would like

  • the width of the first child (image-containing) div to shrink to fit the width of the image (this i can do)
  • the parent div (of unspecified width) to shrink to fit the width of the image-containing div (this is ok too)
  • the text-containing second child div (also of unspecified width) to match the parent div’s width irrespective of the quantity of text it contains (this is where it gets tricky).

I have a working version that does what I want until the quantity of text in the second child pushes the parent div’s width wider than that of the image.

Here’s my code:

css:

#container{border:1px solid #f00;display:inline-block;}
#child1{border:1px solid #0f0;}
#child2{border:1px solid #00f;}
img {border:1px solid #000;}

html:

<div id="container">
<div id="child1"><img src="//www.google.com/logos/2012/Teachers_Day_Alt-2012-hp.jpg" width="300" height="116"></div>
<div id="child2">Lorem ipsum dolor sit amet.</div>
</div>

and here’s a jsfiddle:
http://jsfiddle.net/BmbAS/1/

you can see where it’s going wrong by clicking the ‘lengthen/shorten text’ link to increase the quantity of text

tldr – i want all the divs to be the same width which is equal to the width of the image

ps. modern browser solution only necessary

  • 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-12T15:22:40+00:00Added an answer on June 12, 2026 at 3:22 pm

    See this edited version of your jsFiddle.

    Here’s what’s added to the CSS:

    #container {
        display: table-cell;
    }
    #child1 {
        display: table-row;
        width: 1px;
    }
    #child2 {
        display: table-cell;
        width: 1px;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two model classes, say parent and child. Parents are created first, and
Say that I have three button elements in one parent div. Assuming that these
I have a parent div , say with id=to-remove This div has multiple children
let say I have a parent element which has so many nested child elements
I have this huge domain object(say parent) which contains other domain objects. It takes
I have a parent component, say P, which has function, say Pfunc. I also
I have two sibling divs sitting below each other, both contained in the same
I am facing one small issue. I want to change the parent div style
Say I have an image in a div <div id=myImage><img src=# id=dragImage></div> I want
I have a big div wit a lot of smaller divs within it. Say,

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.