tags:

views:

41

answers:

3

I'm not really sure what I need here but I want to position a div at the bottom of a nested table.

I have an outer table that is 100% wide and no height attribute. I have another table within that outer table where I am using the div. I want the div content to rest on the bottom of the inner table. I currently have the div in a <td> tag.

I've tried to use position:absolute; bottom:0; left:0; but it puts the div and its content at the very bottom of my screen.

How can I do this?

BTW: I know that I should be using 100% css on this project but I'm making a gradual transition. :)

Here is my code for the div

#messageBox {
width:95%;
height:35px;
margin:10px;
padding:10px;
font-family:Arial;
font-size:18px;
}

Here is the table code

<table cellpadding="0" cellspacing="0" border="0" style="width:60%;margin-left:auto;margin-right:auto;margin-top:30px;border:0px solid">
 <tr>
   <td colspan="2" style="height:85px;"><div id="messageBox">test</div></td>
 </tr>
</table>
A: 

Oh the joys of working with tables. It seems that this won't work unless you set the display property of the table to block

You can try giving the outer innermost (my eyes failed me, sorry) table this style:

position: relative;
display: block;

You'll also need to add back in the position: absolute (I see you've taken that out, that is actually the correct method to use for this)

#messageBox {
    position: absolute;
    bottom: 0;
}

Do remember that this will change how the table works, and will probably break your site. See: http://jsfiddle.net/5xTXU/

Yi Jiang
Thanks Yi, but that didn't do anything. What css code should I be using for the div?
Nick
Yi, I tried that and the only thing that I can see that is different is that my table shrinks a bit but all elements are still positioned in the same place.
Nick
+1  A: 

You need to set the <td> element in question to position: relative;. This way any absolutely positioned element will be positioned relative to it.

BalusC
Thanks Balis. I tried that but didn't get anything different. Let me edit my post to include my css.
Nick
Did you keep the `<div>` as `position: absolute; bottom: 0;`?
BalusC
@Balus, I didn't. I changed it back. What I currently have is exactly what I posted up top. I figured I'd wait for someone to tall me what to change
Nick
I thought that *"any absolutely positioned element"* in my answer is self-explaining.
BalusC
Sorry Balus but I don't know much css. I've added `position: relative;` to the `<td>` tag but nothing changes.
Nick
Balus, you are talking about the TD tag that encompasses the div tag, correct?
Nick
The `<td>` should have `position: relative; display: block;` and the `<div>` inside `<td>` should have `position: absolute; bottom: 0;`. An alternative is to give the `<td>` a `vertical-align: bottom;` as answered by Jeaffrey, but this would affect **all** content of the `<td>`. Not sure if this is what you want.
BalusC
A: 
#messageBox {
    width:95%; /* wrong calculation when you add with margin/padding makes overflow */
    height:35px;
    margin:10px;
    padding:10px;
    font-family:Arial;
    font-size:18px;
    border:1px solid red;
}

<table>
    <tr>
      <td colspan="2" style="height:185px; border:1px solid black; vertical-align:bottom;">
        <div id="messageBox">test</div>
      </td>
    </tr>
</table>

I changed your td's height from 85px to 185px to make it obvious.

Preview:

alt text

Request (not overflow):

I'm using additional wrapper.

<table>
    <tr>
      <td colspan="2" style="height:185px; border:1px solid green; vertical-align:bottom;">
        <div style="overflow:hidden; border:1px solid red;">
            <div style="border:1px solid black; float:left; width:100px; margin:10px; padding:0px;">Test</div>
        </div>
      </td>
    </tr>
</table>

Preview:

alt text

Jeaffrey Gilbert
Jeaffrey, thanks. I have been playing around with this while waiting for someone to help me and I have tried the vertical-align attribute which does in fact position the div at the bottom. I'm also noticing that my div goes outside the td box. I'd like the with of the div to be 100%. How should I handle this?
Nick
Ok, I'm out of here. I'm giving you the credit because, even though this is still not working, it is the only answer that did somewhat of what I wanted. Thanks.
Nick
I've updated the answer, Nick. Maybe it's quite different from previous one.
Jeaffrey Gilbert