如何在 Firefox 中将元素放置在其容器的底部?
我有一个表格单元格,我希望其中的 div 始终位于左下角。 以下内容在 IE 和 Safari 中工作正常,但 Firefox 将 div
绝对定位在页面上,而不是在单元格内(基于解决方案解决方案的代码 此处)。 我已经测试了使用和不使用 DTD 的情况,这使 Firefox 处于 Quirks 模式和 Standards 模式,但都无法正常工作。 我被困住了 - 有什么想法吗?
<!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; 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>
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">
<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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
根据 W3C,position:relative 对 table 没有影响细胞:
方案是向表格单元格添加一个额外的环绕 div。
编辑:此 div 需要
height:100%
和position:relative;
待设置。According to the W3C, position:relative has no effect on table cells:
The solution is to add an extra wrapping div to the table cell.
EDIT: This div requires a
height:100%
andposition:relative;
to be set.看看这是否适合你。 不确定问题的确切性质,但它与使用 td 和相对定位有关。 我用 div 标签包裹了表格并相对定位它,它似乎做了你想要的。
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.
在桌子上放置一个
display:block
,现在 FF 会尊重position:relative。Put a
display:block
on the table and now FF respects the position:relative.position:relative
显然不支持td
标签的全局支持。 不幸的是我找不到确切的来源。您可能希望将一个
div
块放入具有所需大小的td
中,并对其应用position:relative
。position: relative
is apparently not globally supported for thetd
tag. I couldn't find definitive sources unfortunately.You might want to put a
div
block into thetd
with the desired size and applyposition: relative
to that instead.这听起来可能很明显,但是您是否尝试过在 .manage 中使用
vertical-align: Bottom;
?This may sound really obvious, but have you tried using
vertical-align: bottom;
in .manage?在 TD 内有一个宽度为 100%、高度为 100% 的 DIV,然后将其设置为位置:相对。
have a DIV inside the TD with width: 100% and height: 100%, then set that to position: relative.
没错,position:relative对于table元素没有影响,firefox应用了这个规则。
div 的解决方案有效,但在我看来这是糟糕的标记。
您绝对需要使用表格来显示此内容吗? (或者它是相对的?)
如果不是,为什么不使用 div 元素并做你想做的事情?
使用表格来解决布局问题已经是 1998 年的事情了……
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...