css - 固定 div 中的图像 - 有趣的 Firefox 行为

标签 css image firefox html

考虑以下示例:( live demo here )

HTML:

<div class="board">
  <div class="row">
    <div class="cell blue"></div><div class="cell"><img src="http://i44.tinypic.com/25sa9z4.png" /></div><div class="cell"></div>
  </div>
  <div class="row">
    <div class="cell"></div><div class="cell"></div><div class="cell"></div>
  </div>
</div>

CSS:

.cell {
  width: 16px;
  height: 16px;
  display: inline-block;
}
.blue.cell {
  background-color: blue;
}
.row {
  height: 16px;
  background-color: #aaa;
}
.board {
  width: 48px;
}

在 Chrome 17 和 Safari 5.1.4 中,蓝色单元格位于第一行,正如预期的那样。
但是,在 Firefox 11.0 中,蓝色单元格位于第二行!

为什么会有这种差异?如何使其保持一致?

最佳答案

查看 fiddle 和演示:

fiddle :http://jsfiddle.net/cSWnb/12/

演示:http://jsfiddle.net/cSWnb/12/embedded/result/

更新的 fiddle :

fiddle :http://jsfiddle.net/cSWnb/23/

演示:http://jsfiddle.net/cSWnb/23/embedded/result/

.cell {
    width: 16px;
    height: 16px;
    display: inline-block;
    vertical-align:top;
}
.blue.cell {
    background-color: blue;
}
.row {
    height: 16px;
    background-color: #aaa;
}
.board {
    width: 48px;
}

见下图:

enter image description here

浆果图像的高度超过了单元格的高度,因此 FF 出现了渲染问题。这是浏览器兼容性问题,chrome 和 safari 是基于 webkit 的浏览器,因此它们的呈现方式相似。在 FF 中,默认情况下元素不是 Vertical-align:top;所以我们必须设置 css 属性以使元素与浏览器兼容。

关于css - 固定 div 中的图像 - 有趣的 Firefox 行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9859040/

相关文章:

html - 链接多个 CSS 动画

html - 小图与大图(重复时)

css - 显示 CSS 代码的 Google 搜索代码段

html - css 中的图像 map 标题?

html - 如何在css文件中左右切换?

ruby - 在 Firewatir 中,如何与 Firefox 打印对话框交互?

javascript - Firefox 是否允许使用 "aggregated"火焰图分析 JS 应用程序?

ruby - Rails 管理员显示 :thumb image

Javascript for 循环使用图像数组作为敌人

html - FireFox 中的 margin 问题