html - 带有填充和溢出的 div 上 firefox 中 scrollHeight 的奇怪行为 :auto

标签 html firefox scrollbar padding

在这里,http://jsfiddle.net/YNKws/

<div id="div1" style="padding: 2px; overflow: auto;">
  <div style="height:30px;">lalala</div>
  <div style="height:30px;">lalala</div>
</div>

var d = $("#div1");
for (var i = 0; i < 5; i++) {
  console.log(d.height(),d[0].scrollHeight);
  d.height(d.height() - 1);
}

有带填充和溢出的 div:auto。在 firefox 中,div 的 scrollHeight 值有奇怪的行为。当我们将 div 的高度设置为小于其原始高度时,很自然地期望滚动条立即出现并且 scrollHeight 值保持不变。 Chrome 适合这些期望但 firefox 不适合,最后一个不绘制滚动条,当原始高度的偏差小于 div 的 padding 时,减少 bottom padding 和 scrollHeight。

这是一个错误吗?这个“错误”是否有修复?

最佳答案

Firefox 的行为是 CSS 规范所要求的:填充溢出的东西本身不会导致溢出。

关于html - 带有填充和溢出的 div 上 firefox 中 scrollHeight 的奇怪行为 :auto,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14899676/

相关文章:

cocoa - 用 Cocoa 应用程序制作一个 Firefox 插件?

javascript - 在 Firefox 中注入(inject) Javascript

javascript - 如何顺利隐藏滚动条?

python - 如何使用 selenium ChromeDriver 滚动 Google map 上的侧边栏以加载更多结果?

javascript - Jasmine 测试在测试运行中、Firefox/Chrome 之间以及检查器打开/关闭时的结果不一致

HTML/CSS : "See Through Background" Text?

wpf - XAML Canvas 上可放大和缩小的滚动条

html - 隐藏 iframe 上的水平滚动条?

html - 在 C++ linux 中使用 log4cplus 将日志写入 html 文件

jquery - 宽度 100% 但额外的宽度使滚动