Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Nov 2008
    Posts
    16
    Thanks
    1
    Thanked 1 Time in 1 Post

    Making a div stretch around contents

    is there a way to make a surrounding div stretch to fit the content of an internal div? example:
    Code:
    <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.

  • #2
    Regular Coder ajhauser's Avatar
    Join Date
    Nov 2007
    Location
    Earlville. It's where Earls come from.
    Posts
    226
    Thanks
    74
    Thanked 1 Time in 1 Post
    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:

    Code:
    <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

    Code:
    <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.
    Last edited by ajhauser; 05-01-2009 at 09:29 AM. Reason: explanation


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •