【问题标题】:CSS Height difference in FirefoxFirefox 中的 CSS 高度差
【发布时间】:2012-03-06 18:31:17
【问题描述】:

我正在尝试使用以下 javascript/jquery 代码将表 (templtableselect) 中第 th 元素的高度设置为与另一个表 (templtable) 中第 th 元素的高度相同:

var thheight = $('table#templtable th').css("height");
$('table#templtableselect th').css({"height":thheight, "border":"0px"});

在 chrome 中一切正常,但在 Firefox 中存在 1 个像素的差异。我也尝试了 .height() 函数,但结果相同。

当我用firebug分析firefox中的元素时,结果如下:

Templtable
size 105 x 34
border 1

Templtableselect
size 44 x 33
border 1

您也可以看到相同的 1 个像素的差异。

知道什么会导致这种差异吗?

谢谢

【问题讨论】:

  • 请提供一些代码(HTML + CSS)。我无法重现此问题。 Firebug 为两个表头显示 100px:jsfiddle.net/tLnTU

标签: jquery css firefox google-chrome height


【解决方案1】:

尝试改用outerHeight(),它会为高度添加边框和内边距。

var thheight = $('table#templtable th').outerHeight();
$('table#templtableselect th').css({"height":thheight, "border":"0px"});

【讨论】:

  • 好点。 @TheCodeBuccaneer 检查两个表是否具有相同的单元格间距、单元格填充等。
猜你喜欢
  • 2019-05-08
  • 2020-08-29
  • 1970-01-01
  • 1970-01-01
  • 2011-11-05
  • 2017-04-08
  • 2011-07-28
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多