html - 为什么 Chrome 没有正确考虑边距?

标签 html css google-chrome margin

找了半天也没找到答案:/

在 Chrome(Internet Explorer、Konqueror 和许多其他浏览器)中,底部的 h1 边距被添加到 .blue。但是,Firefox 会正确遵守 css 规则。

有什么建议吗?

HTML

<div class="red"><div class="blue"><h1>Hello World!</h1></div></div>

CSS

.red{
  background: red;
  /* All this contain margins */
  float:left;
  /* padding-top:1px; */
  /* display: inline-block */
  /* overflow: hidden */
}

.blue{
  background: blue;
  min-height: 60px;
}

h1{
  margin: 10px 0 20px;
  background: green;
}

基于 Gecko 的:[我猜这是正确的]

enter image description here

基于 Webkit、KHTML 和 Trident shell:

enter image description here

CODEPEN

http://codepen.io/marquex/pen/fzsIk

最佳答案

您遇到的边距问题与 .blue div 中的 min-height 规则有关。如果可以在 Chrome 和 Firefox 中获得相同的结果,请将其替换为 height 规则。

虽然我不知道为什么在使用 min-height 时会发生这种情况。也许是某种 Chrome 的错误。

关于html - 为什么 Chrome 没有正确考虑边距?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22910158/

相关文章:

sqlite - 如何使用 powershell 读取/解密 chrome sqlite 数据库中的 crypto_value 列?

php - 推荐的 Twig 文件扩展名

javascript - jQuery 自定义内容滚动条遍历路径样式 :)

css - 悬停时 WordPress 子菜单项未正确显示

javascript - Chrome 跨站点资源 - 网站无法正常工作

jQuery 代码在 Chrome 和 IE 中无法正常工作

php - 如何保护父级样式免受用户在描述字段中添加的样式的影响

html - 如果我只需要在一页中使用粘性页脚怎么办?

html - 位置 :fixed "hitboxes" move up in iOS 10 Safari on Plus-sized phones when tab bar is shown

javascript - 防止在带有 Canvas 的页面上的移动设备上滚动