...

View Full Version : Making a div stretch around contents



queirdo
05-01-2009, 08:17 AM
is there a way to make a surrounding div stretch to fit the content of an internal div? example:


<div id="container">
<div id="content">
<p>Here is a lot of content....</p>
<p>Here is a lot of content....</p>
<p>Here is a lot of content....</p>
<p>Here is a lot of content....</p>
</div>
</div>


I want to align a background image to the bottom of the #container div (can't put it at the bottom of the content div because of margins in the real page), but I want it to appear underneath the content. It seems that when I do something like above, the #container div will end before the content div ends, so any background will be in the middle of the text near the top.

ajhauser
05-01-2009, 09:28 AM
Unless your "<div id="content">" is floated it should already be surrounded by the container div. This may also be why the container div content is showing up first.

Is that the case?

If the content div is NOT floated, you could just add in an image or another div altogether below it and it should display correctly. For example:



<div id="container">
<div id="content">
<p>Here is a lot of content....</p>
<p>Here is a lot of content....</p>
<p>Here is a lot of content....</p>
<p>Here is a lot of content....</p>
</div>
<img src="">here_isa_sweet_image_underneath.jpg
</div>


or



<div id="container">
<div id="content">
<p>Here is a lot of content....</p>
<p>Here is a lot of content....</p>
<p>Here is a lot of content....</p>
<p>Here is a lot of content....</p>
</div>
<div id="content_footer">
*style this div and add additional content here*
</div>
</div>


Both of these methods should cause the container div to expand - UNLESS you have the container defined with a set height or width.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum