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

  • Home
  • SEARCH
  • 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 5954709
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:00:34+00:00 2026-05-22T18:00:34+00:00

If two divs are floated in a table cell, and the text are short,

  • 0

If two divs are floated in a table cell, and the text are short, they float nicely on the same level.

But when the second div has longer text, the 2 divs now don’t float on the same level.

Why is that and how to make it work, without specifying a hard-coded width for the 2nd div? (because dynamic width is needed if other table cells are wider or not as wide)

A code example is in:
http://topics2look.com/code-examples/two-floats-in-a-table/

The first hello is floated left (it actually is supposed to be an image of + or - using CSS image sprite, but just made simple here). The “world world” is supposed to be the description and float nicely next to the image.

So the first table is all ok. But in the second table, it has “world world world … world” and is quite long. Now the second div will not float next to it but will float under the first float. Is there a way to make it shrink wrap better so that it floats nicely next to the first div?

  • 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-22T18:00:34+00:00Added an answer on May 22, 2026 at 6:00 pm

    don’t float the second div, then add overflow: hidden; (or auto) to it to make is anew block formatting context, should achieve what you need:

    CSS:

    body { 
       font: 16px Verdana, sans-serif;
    }
    
    #main-content { 
       width: 600px; 
       border: 6px double black; 
       margin: 20px 0;
    }
    table { 
       border: 6px double orange;
    }
    
    table div { 
       float: left; 
       padding: 4px;
    }
    
    table div+div {
       float: none; 
       overflow: hidden;
    }
    

    HTML:

    <table>
       <tr>
          <td><div>hello</div> <div>world world world world world world world world world</div></td>
          <td><div>hello</div> <div>world world world world world world world</div></td>
       </tr>
    </table>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a div with two nested divs inside, the (float:left) one is the
I have a container div that holds two internal divs; both should take 100%
Two divs, floated left, of unknown width. One of them has more content than
I'm trying to put two divs on the right side of parent div one
i have two divs one floated to the left and the other to the
The idea: I have a container div with two divs inside of it, like
As a web developer I frequently will have two floated (child) divs inside of
Really simple question time: I have two divs. <div id=1> <p>hello</p> </div> <div id=2>
I am looking for two divs that look like this: <div style=height:20px; /> <div
i have two divs side by side (via float:left). on this two divs i

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.