views:

2414

answers:

7

I have a table cell, and I want a div within it to always be at the bottom left corner. The following works fine in IE and Safari, but Firefox is positioning the div absolutely on the page, not within the cell (code based on the solution solution here). I have tested both with and without the DTD, which put Firefox in Quirks mode and Standards mode, and neither worked properly. I'm stuck - any ideas?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
     <title>Test</title>
     <style type="text/css">
     table { width:500px; }
     th, td { vertical-align: top; border:1px solid black; position:relative; }
     th { width:100px; }
     .manage { text-align:right; position:absolute; bottom:0; right:0; }
     </style>
    </head>
    <body >
    <table>
     <tr>
      <th>Some info about the following thing and this is actually going to span a few lines</th>
      <td><p>A short blurb</p><div class="manage">Edit | Delete</div></td>
     </tr>
     <tr>
      <th>Some info about the following thing and this is actually going to span a few lines</th>
      <td><p>A short blurb</p><div class="manage">Edit | Delete</div></td>
     </tr>
    </table>
    </body>
</html>
+1  A: 

See if this works for you. Not sure of the exact ature of the problem but it has something to do with using td with relative positioning. I wrapped the table with div tag and positioned that relatively and it seems to do what you want.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
        <title>Test</title>
        <style type="text/css">
        table { width:500px;  }
        th, td { vertical-align: top; border:1px solid black; }
        th { width:100px; }
     div.body {position:relative; width:500px;}
        .manage { text-align:right; position:absolute; bottom:0; right:0; display:block}
        </style>
    </head>
    <body >
    <div class="body"><table>
        <tr>
                <th>Some info about the following thing and this is actually going to span a few lines</th>
                <td><p>A short blurb</p><div class="manage">Edit | Delete</div></td>
        </tr>
    </table></div>
    </body>
</html>
Salt Packets
Unfortunately, this one breaks when I add another row to the table that looks the same.
Chris Marasti-Georg
A: 

position: relative is apparently not globally supported for the td tag. I couldn't find definitive sources unfortunately.

You might want to put a div block into the td with the desired size and apply position: relative to that instead.

_Lasar
Trying this, I can't get the div to fill the td.
Chris Marasti-Georg
A: 

This may sound really obvious, but have you tried using vertical-align: bottom; in .manage?

R. Bemrose
+3  A: 

According to the W3C, position:relative has no effect on table cells:

"The effect of 'position:relative' on table-row-group, table-header-group, table-footer-group, table-row, table-column-group, table-column, table-cell, and table-caption elements is undefined."

The solution is to add an extra wrapping div to the table cell.

EDIT: This div requires a height:100% and position:relative; to be set.

<table>
    <tr>
        <td>
            <div style="position:relative;height:100%;">
                Normal inline content.
                <div class="manage">your absolute-positioned content</div>
            </div>
        </td>
    </tr>
</table>
Aron Rotteveel
That doesn't push it to the bottom :(
Chris Marasti-Georg
edited code example now. I tested this in Firefox 3 and it works.
Aron Rotteveel
In FF3, this is not pushing to the bottom for me. http://i36.tinypic.com/znqxpv.jpg
Chris Marasti-Georg
A: 

have a DIV inside the TD with width: 100% and height: 100%, then set that to position: relative.

jishi
This does not work - the inner div does not get pushed to the bottom.
Chris Marasti-Georg
A: 

Right, position:relative has no effect for table elements, and firefox apply this rule. The solution of the div works, but this is terrible markup in my opinion.

Do you absolutely need to use a table to display this content? (Or is it relative?)

If not, why don't you use div elements and do what you want?

To use tables for layout issues is so 1998...

alexmeia
The data I am displaying is tabular. One column displays context for a comment, the other column displays the comment itself. Why use an element with no semantic meaning when a semantically rich one is provided, that fits my case?
Chris Marasti-Georg
Ok, but a definition list (dl) instead of a table can be a semantic solution as well.
alexmeia
They are not really definitions. Is there a way to make sure both dt and dd stay the same height as content changes?
Chris Marasti-Georg
This can be a solution:http://www.maxdesign.com.au/presentation/definition/dl-table-display.htm
alexmeia
I got very excited - it seemed to do everything I needed. Even got a border between the left and right sides (dt and dd). Unfortunately, if the dt content is longer than the dd content it breaks in IE.
Chris Marasti-Georg
+1  A: 

Put a display:block on the table and now FF respects the position:relative.

Wouter
+1 this sure makes it work!
Frankie