1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Stick something to Bottom of DIV

Discussion in 'CSS' started by wd_2k6, Jun 26, 2008.

  1. #1
    Hi I have a DIV which has a min-height of 300px, in fact the DIV is unlikley to surpass this so we could say it has a height of 300px.

    This DIV will contain some text, and another DIV inside it. How can i ensure this secondary DIV always appears at the bottom, regardless of how long or short the dyanmic text is.

    I guess we can't use margin or padding, because the text above the DIV is dyanmic, therefore we couldn't calculate it?

    The second DIV I want to appear at the bottom isn't dynamic and has a fixed height of 24px?

    Hmm I have an idea actually, if I have the secondary DIV appear after the main DIV is closed, so that it is not nested inside it, and shove a negative margin of -24px on it could be a way.

    Maybe I could use some positioning?
     
    wd_2k6, Jun 26, 2008 IP
  2. Ulquiorra

    Ulquiorra Peon

    Messages:
    422
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    0
    #2
    put the text in a div as well, and assign that div a height of 300 minus 24 (if you have no paddings).
     
    Ulquiorra, Jun 26, 2008 IP
    wd_2k6 likes this.
  3. wd_2k6

    wd_2k6 Peon

    Messages:
    1,740
    Likes Received:
    54
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Yes that's what i've done thanks for the help, I thought of it as I was writing the post, why wasnt i just creating the DIV as height of 276px!! Silly me, thanks for the help !!
     
    wd_2k6, Jun 26, 2008 IP
  4. steelfrog

    steelfrog Peon

    Messages:
    537
    Likes Received:
    24
    Best Answers:
    0
    Trophy Points:
    0
    #4
    That wouldn't work if the div ended up longer than 300px. If I understand what you're trying to do, you could also place another div under that one and set it to a negative margin.

    div.whatever { margin-top: -30px; }
    Code (markup):
     
    steelfrog, Jun 27, 2008 IP
  5. yankzilla

    yankzilla Peon

    Messages:
    159
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #5
    What you could do is something like this...

    
    
    <div style="height: 300px; background-color: red; width: 100px">
     <div style="position: relative; top: 274px; height: 24px; width: 100px; background-color: green"> 
      test
     </div>
    </div>
    
    
    Code (markup):
    Of course you can change all the info in it, such as the colors, width etc. Those were jsut used so you can see the change in the divs easier.

    Cheers.
     
    yankzilla, Jun 27, 2008 IP
  6. Stomme poes

    Stomme poes Peon

    Messages:
    3,195
    Likes Received:
    136
    Best Answers:
    0
    Trophy Points:
    0
    #6
    I wouldn't do it that way-- position relative changes where it visually is, not where it really is-- might as well take it out of the document entirely anyway then (otherwise if the div gets higher than 300px (as it would with just a single text enlarge, or simply viewing on my machine which makes fonts a bit larger than normal, Linux machine) then div2 will not get out of the way).
    top: 274px;
    Doesn't work when the content of div1 grows... but you could do this:

    div1 {
    position: relative;
    min-height: 300px;
    padding-bottom: 24px; (this is the flaw in this plan, except you won't see this space at the bottom because the second div will always be in there...)
    }
    div2 {
    position: absolute;
    bottom: 0;
    set left: 0 here too;
    height: 24px;
    }

    It will always sit at the bottom of its positioned parent, and the div1's bottom padding prevents the content of div1 from covering div2.
     
    Stomme poes, Jun 28, 2008 IP