简体   繁体   English

为什么Chrome不能正确遵守利润率?

[英]Why Chrome doesn't respect the margin properly?

I search for a long and I can't find an answer :/ 我搜索了很长时间,但找不到答案:/

In Chrome (Internet Explorer, Konqueror, and many others) the h1 margin at bottom is added to .blue . 在Chrome浏览器(Internet Explorer,Konqueror等)中,底部的h1边距将添加到.blue However, Firefox respect the css rules properly. 但是,Firefox会正确遵守css规则。

Any suggestion? 有什么建议吗?

HTML 的HTML

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

CSS 的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-based: [This one is the correct, I guess] 基于壁虎: [我猜这是正确的]

在此处输入图片说明

Webkit-based, KHTML-based and Trident shell: 基于Webkit,基于KHTML和Trident的shell:

在此处输入图片说明

CODEPEN CODEPEN

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

The margin issue you are having is related with the min-height rule in the .blue div. 您遇到的边距问题与.blue div中的min-height规则有关。 Replace it for a height rule if it is possible to get the same result in Chrome and Firefox. 如果可以在Chrome和Firefox中获得相同的结果,则将其替换为height规则。

I have no idea why that is happening when using min-height though. 我不知道为什么使用min-height时会发生这种情况。 Maybe is some kind of Chrome's bug. 也许是Chrome的某种错误。

Define your fonts, this is the problem, every browser have different settings for default fonts, headings (h1...h6) respectively. 定义字体,这就是问题所在,每个浏览器对默认字体,标题(h1 ... h6)都有不同的设置。 So the actual height of the text in h1 will be different and this is the cause for different margins at bottom/top . 因此, h1本的实际高度将有所不同, 这是导致bottom / top的边距不同的原因

As you can see, Gecko-based browser uses a sort of Garamond -styled font, all other use by default Times New Roman , of course if user was predefined the fonts for pages, sometimes everything may look the same across all browsers, example: 如您所见,基于Gecko的浏览器使用某种Garamond样式的字体, 默认情况下所有其他使用Times New Roman ,当然,如果用户已为页面预定义了字体,则有时在所有浏览器中看起来都一样,例如:

h1{
  margin: 10px 0 20px;
  background: green;
  font-family: "Your-favorite-font", Times, sans-serif;
  font-size: 2em;
}

RESOLVING 解决

After a long search I reported the issue on chromium repo. 经过长时间的搜索,我报告了有关铬回购的问题。 And they accept it as a bug . 并且他们接受它作为错误 So, if anyone wants to know the final of this history can follow the fix process here . 因此,如果任何人想知道此历史记录的最终版本,都可以按照此处的修复过程进行操作。 Thanks anyone who try to help us, but let me add that I did not believe that Stackoverflow can be able to not see an error of this magnitude. 感谢所有尝试帮助我们的人,但我要补充一点,我不认为Stackoverflow看不到如此严重的错误。 I am a little less stackoverflowita . 我少了stackoverflowita

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM