Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DIV issues.

Status
Not open for further replies.

Albion

IS-IT--Management
Aug 8, 2000
517
US
I have two DIV containers. I would like to be able to dynamically position one DIV inside of the other where the container DIV expands to fit the first. Problem is when I make the container DIV position:relative and the dynamic DIV position:absolute the dynamic DIV will position itself inside of the container DIV but the container DIV will not expand height wise to fit the DIV inside. So I get something like this.

Code:
+--------------------------+
| +---------+              |
+-|         |--------------+
  |         |
  +---------+

When I want this

Code:
+--------------------------+
| +---------+              |
| |         |              |
| |         |              |
| +---------+              |
+--------------------------+

Is there any way without using a static height to get a container DIV to expand to the height of it's dynamic contents?

Thanks

-Craig
 
Is there a reason that you want to position one div relative and the other absolute??

Without floating the inner div, the outer div should automatically expand to fit the inner div, height and width, if you write your structure like this:

Code:
<div id="outerDiv">
   <div id="innerDiv">
      content
   </div>
</div>

If you float the inner div, you either specify a height on the outer div or just clear the float in a div just above the outerDiv closing tag:

Code:
<div id="outerDiv">
   <div id="innerDiv" style="float:left">
     content
   </div>
   <div id="floatBreaker" style="clear:left"></div>
</div>

+--------------------------+
| +---------+ |
| | | |
| | | |
| +---------+ |
+--------------------------+


[monkey][snake] <.
 
Code:
<div style="background: red;">
  <div style="width: 50%; background: blue;">
    Some text and more text and stuff <br />
    Some text and more text and stuff <br />
    Some text and more text and stuff <br />
  </div>
</div>
This will do exactly what you want, but the question is, why were you complicating so much...
 
Is there a reason that you want to position one div relative and the other absolute??"

Yes, because I want to be able to position the inner DIV anywhere within the outer DIV dynamically based on X,Y coordinates I pull from a database.
 
In that case why not make the height of the outer DIV based off of the Y coordinate that you pull from the database?



[monkey][snake] <.
 
Ah ha! That's not a bad idea. I will try that.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top