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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:20:14+00:00 2026-06-15T14:20:14+00:00

HTML <div class=cont> <div class=size id=size1></div> <div class=text>Here is some textHere is some text

  • 0

HTML

<div class="cont">
<div class="size" id="size1"></div>
<div class="text">Here is some textHere is some text Here is some text</div>
</div>

<div class="cont">
<div class="size" id="size2"></div>
<div class="text">Here is some textHere is some text Here is some text</div>
</div>​

CSS

.size {
    background-color: red;
    height: 100px;
    width: 100px;
}
#size2 {
    width: 200px;
}
.cont {
    padding: 10px;
    float: left;
}​

I need div.cont‘s widths to be the width of their contained div.size (in my actual example div.size is an image and its with will vary in each instance).

This isnt happening as div.text takes up more space than its container, how can I stop this and make the text wrap?

JS Fiddle

  • 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-15T14:20:14+00:00Added an answer on June 15, 2026 at 2:20 pm

    Deleted all the previous stuff as I have (after doing some digging) found an exact duplicate with working solution.

    My answer was also incorrect (as the op then specified the image MUST be allowed to be variable)

    The answer is found on this jsfiddle and is an exact duplicate of css – shrink a parent div to fit one child's width and constrain the width of the other child

    //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>
    <br/>
    <a id="longtext" href="#">lengthen/shorten text</a>
    

    //css

    #container{border:1px solid #f00;display:inline-block;margin:10px; display: table;}
    #child1{border:1px solid #0f0;margin:10px; display: table-row; width: 1px;}
    #child2{border:1px solid #00f;margin:10px; display: table-cell; width: 1px;}
    img {border:1px solid #000;}
    

    and basically it works using display:table-* (have a good read up)

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

Sidebar

Related Questions

I am using Jquery Accordian in my page, Here is the HTML, <div class=forms-cont>
<div class = a> <div class = a b> text </div> </div> <script> alert($(.a).html());
Fiddle is here - http://jsfiddle.net/ashwyn/a45ha/ HTML here - <div class=parent> <div class=a>Class A</div> <div
So I have some html that looks like the following: <div class='something unknown' id='something_unknown_1'>
Suppose I have the following html: This a test of <code>some code</code>. <div class='highlight'>
I appended some div like this : var to = Some content $(#key).append(<div class=\cont\>+to+
This is my code: HTML <div class=popup> <div class=popup-frame> <div class=popup-cont> <div class=inner></div> </div>
I need to convert my PHP array in to html with some div class.
i have my html something like this... <div class = content> <div class =
Is this html <div class='title centered'>SCE</div> <div class='description'> Magna tristique pulvinar porta montes, scelerisque

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.