How can I position an element at the bottom of its container in Firefox?

纵然是瞬间 提交于 2019-11-30 18:36:10

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>

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">
<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>
Wouter

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

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.

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

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

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...

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!