html - 如何在 TD 或 TH 中定位元素而不在 Firefox 中收到警告?

标签 html css firefox warnings css-position

我在表头单元格中使用绝对定位的元素。为此,TH 必须自行定位,使其成为子元素的 offsetParent(在我的例子中,使用 position:relative)。不幸的是,当前的 Firefox 版本似乎会在 TD 或 TR 被指定为非静态位置时发出警告。

使用以下最小表格 HTML

<table>
<tr><th>head</th></tr>
<tr><td>cell</td></tr>
</table>

以及以下最小 CSS 规则

th { position: relative }  // either of these is enough
td { position: relative }  // to trigger the warning
table { border-collapse: collapse }

此警告出现在 Firefox 30 和 32 的控制台中:

Relative positioning of table rows and row groups is now supported. This site may need to be updated because it may depend on this feature having no effect.

(当表格边框保持独立时,不会出现警告)

这条消息的来源是Firefox's table layout code :

/* static */ void
nsTableFrame::RegisterPositionedTablePart(nsIFrame* aFrame)
{
  // Supporting relative positioning for table parts other than table cells has
  // the potential to break sites that apply 'position: relative' to those
  // parts, expecting nothing to happen. We warn at the console to make tracking
  // down the issue easy.

因此,即使我们根本没有做错任何事情,我们也会收到此警告,因为其他网站可能依赖 position 规则“什么都不做”。有没有办法摆脱这个烦人的警告?它基本上是在告诉我:警告,你所做的事情确实有效!

最佳答案

我收到了同样的警告,并通过将定位应用于 th 或 td 内的 div 而不是直接应用于 td 或 th 来解决它。不知道为什么它在乎,但现在我不需要再看到它了。

td div{position:relative;}

<table>
  <tr>
    <td>
      <div></div>
    </td>
  </tr>
</table>

关于html - 如何在 TD 或 TH 中定位元素而不在 Firefox 中收到警告?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26305219/

相关文章:

html - ASP.Net 菜单在 IE 中表现异常

javascript - 强制页面不向下滚动并保持 100% 窗口高度的 CSS 或 JS 解决方案

php - 找到所有的 <img> 标签,去掉 height 和 width 然后把去掉的值放在 <img> 标签的样式中

java - 如何使用 JSS 将受信任的证书颁发机构添加到 Firefox

javascript - ASCII 代码在 Firefox 中不起作用,但在 Chrome 上工作正常

http - 为什么 Firefox 不发送 If-Modified-Since header ?

javascript - SapUI5 表 - 404 未找到错误

Javascript ES6 代码优化

html - map 上的非绝对或固定 div

javascript - 使用不带节点图标的 dynaTree