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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T05:59:03+00:00 2026-05-12T05:59:03+00:00

I have the following HTML snippet: Block 1: <div style="position: absolute; top: 105px; left:

  • 0

I have the following HTML snippet:

Block 1:
<div style="position: absolute; top: 105px; left: 15px;">
    <div style="float: left; width: 50px; height: 40px;"></div>
    <div style="float: left; width: 100px; height: 20px;"></div>
</div>

Block 2:
<div style="position: relative; width: 60px; height: 20px;">
    <div style="position: absolute; top: 15px; left: 15px;">
        <div style="float: left; width: 50px; height: 40px;"></div>
        <div style="float: left; width: 100px; height: 20px;"></div>
    </div>
</div>

Block 1 is an ordinary absolute positioned DIV, while in block 2, the same DIV is enclosed within a relative positioned DIV.

My problem is, on Block 2, the absolute DIV inherits the width property from its parent, thus rendering the child DIVs on top of each other. Compare that to Block 1 where the child DIVs are floated side by side properly (because maximum allowable width is assigned).

Is there any fix for this situation? The height and width given are arbitrary and can change at any time. The child DIVs shouldn’t set any width because the content keeps changing (I put some here for illustration purposes). I can set a certain width, but people with different browsers and DPI settings keep getting different result, so it’s best to keep the child DIVs’ width unset.

Update for bounty:

The intended usage of the above HTML is similar to the following:

Block 2:
<div id="main" style="position: relative; width: 60px; height: 20px;">
    Main Text
    <div id="columncontainer" style="position: absolute; top: 20px; left: 0px; width: 100px;">
        <div id="leftcolumn" style="float: left;">
                Item 1: Left Column, Line 1<br />
                Item 2: Left Column, Line 2<br />
                Item 3: Left Column, Line 3<br />
        </div>
        <div id="rightcolumn"  style="float: left;">
                Item 4: Right Column, Line 1<br />
                Item 5: Right Column, Line 2<br />
        </div>
    </div>
</div>

Notes:

  • leftcolumn and #rightcolumn width is not static, so there’s no specific width that can be set. The width should follow the longest text (each item in a single line).

  • I can set #columncontainer width to a specific width (which I am doing right now), but if the text is too long, then the left-right column is messed up (#rightcolumn below #leftcolumn, which is correct because of not enough space).
  • main width is set to a specific width, which in all possible case will be much less than #columncontainer width.

  • I’m open for JS solution, as that may seem to be the only consistent solution I can think of.
  • 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-12T05:59:04+00:00Added an answer on May 12, 2026 at 5:59 am

    In Block 2, the absolutely positioned div doesn’t strictly inherit its width from its parent. If that were the case, setting its width to auto would do the trick. Instead, its relatively positioned parent has become its “containing block“, establishing a context inside which the absolute div lives, so to speak.

    The only way to “break out” of that containing block is to set a width on it so it overflows, as you were doing. If you set that width to a value that will usually be good enough, you could further control how the floats inside it behave by setting (percentage) min-width and max-width values on them.

    But do you really need the #columncontainer div to be inside #main, other than to position it relative to #main‘s coordinates?

    What you could do instead is make them siblings in a common parent div (the rest of the CSS remains the same):

    <div style="position: relative">
        <div id="main">...</div>
        <div id="columncontainer">...</div>
    </div>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following HTML code snippet: <li>2011-10-17</li> <li><p><img style=float: left; alt=photo1 src=/images/stories/site/news/photo1.jpg height=148 width=217>Some
I have the following snippet in one of my html pages : <div class=inputboximage>
I have the following html snippet: <div id=contentX><h1>MyHeading1</h1></div> I could select with jQuery snippet
I have the following HTML snippet <div id=column_1> <div id=portlet_1> <div id=portlet-header_1> <input type=button
Let's say I have the following HTML snippet: <div abc:section=section1> <p>Content...</p> </div> <div abc:section=section2>
I have following html snippet: <div class=rsw-pp rsw-pp-widget> <div g:type=AverageStarRating g:secondaryurls=http://maps.google.com/?cid=12948004443906002997 g:decorateusingsecondary=http://maps.google.com/?cid=12948004443906002997 g:groups=maps g:rating_override=2.998000
I have a repeater containing the following HTML snippet: <div id='parent'> <div id='child1'/> <div
Consider the following HTML snippet. The desired effect is to have a dropdown be
From this site: http://www.toymaker.info/Games/html/vertex_shaders.html We have the following code snippet: // transformations provided by
I have the following HTML node structure: <div id=foo> <div id=bar></div> <div id=baz> <div

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.