Getting <div> to expand with content?

Discussion in 'HTML & Website Design' started by cscott5288, Feb 7, 2009.

  1. #1
    Ok, So I have this class:

    div.blogtap-09_ {
    background-image: url('images/leftpanel_bg.jpg');
    background-repeat: repeat-y;
    position:absolute;
    left:0px;
    top:323px;
    width:554px;
    min-height: 300px;
    height: 0 auto;
    overflow:auto;

    In this wrapper:

    div.Table_01 {
    position:absolute;
    left:0px;
    top:0px;
    width:785px;
    height:680px;
    }

    It's basically a <div> with a background repeating vertically (y). What I can't figure out is how to get the <div> to expand (vertically) when the content (text in my case) reaches the end of the <div>. I have tried messing with the overflow, and have had no luck.

    For some reason, it won't display text after a certain point. It acts like overflow:hidden, even when it's not set to that!

    How do I do this???

    Thanks ahead!
     
    cscott5288, Feb 7, 2009 IP
  2. cscott5288

    cscott5288 Active Member

    Messages:
    912
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    60
    #2
    Ok, I think i figured out what's going on here.

    I am using absolute positioning. So the div element does expand, it just expands after all of the other <divs> because those other <divs> are absolutely positioned right after the blogtap-09_ div. So, how do I position the other divs without using absolute positioning, so that they will position right after blogtap-09_ div, but not dissrupt the overflow (div expansion) ?
     
    cscott5288, Feb 7, 2009 IP
  3. wd_2k6

    wd_2k6 Peon

    Messages:
    1,740
    Likes Received:
    54
    Best Answers:
    0
    Trophy Points:
    0
    #3
    A DIV by default should automatically extend with content vertically, unless you give it a max-height, or height with some overflow settings.
    Absolute Positioning should only be used when you need it, you should use floats to position DIV elements around the page, then use absolute positioning if needed which is rare.
    For example:
    <div>Text 1</div>
    <div>Text 2</div>
    Without adding any styles at all Text 2 will always be underneath Text 1, and text 1 will expand with content.

    DIV's by default appear underneath one another (they are block level elements) and this is the case unless you position DIV's or float them (but floats can be cleared also). So i'm guessing your maybe making things more difficult than they are but can't tell without seeing anything or any code !
     
    wd_2k6, Feb 7, 2009 IP
  4. cscott5288

    cscott5288 Active Member

    Messages:
    912
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    60
    #4
    i pretty much just figured out what you said, right before you said it!

    thanks though!

    p.s. they should add what you said in online CSS tutorials. many major ones (like w3 schools) are lacking that explanation.
     
    cscott5288, Feb 7, 2009 IP
  5. wd_2k6

    wd_2k6 Peon

    Messages:
    1,740
    Likes Received:
    54
    Best Answers:
    0
    Trophy Points:
    0
    #5
    no problem, it's good you worked towards a solution yourself!
     
    wd_2k6, Feb 7, 2009 IP