与 IE9 相比,Firefox 似乎在大多数元素的顶部添加了 3px
还有一个“Firefox 不同意 IE9”以及相反的问题。
我可以解释发生了什么,但一张图片说了一千多个字,所以我拍了一张 FF 和 IE 的屏幕截图:
这是标记:
<div align="center" id="cmContainer" style="background-color: #8CFE70; border: 1px solid #2D9500; border-radius: 4px; width: 400px; height: 161px;">
<span style="color: #2C2C2C; font-family: Arial; font-size: 20px; text-align: center;" />
<font size="24">Look!</font>
<br>
See how different IE renders from FF?
<br>
How can I fix this?
</span>
<br>
<input value="CODE" type="text" size="20" style="font: 20px Arial; color: #000000; background-color: #F3F3F3; border: 1px solid #8D8D8D; width: 300px; border-radius: 2px; text-align: center; margin-top: 0px; padding: 5px 3px 5px 3px; " />
<br>
<input type="button" value="I'm a button!" />
</div>
是什么原因导致的?我用 Firebug 尝试了几种不同的东西,但没有成功。
为什么 Web 开发必须如此烦人? :)
PS:在评论我对内联样式的使用之前,请注意这是我的项目所需要的。 :)
编辑:按照 Cygal 和 Christophe 的建议,通过使用 CSS 重置,并仅将其应用于我的对象,结果如下:
真的不能要求更好的东西了,正如 easwee 所指出的那样。 ;)
Yet another "Firefox does not agree with IE9" and the other way around problem.
I could explain what is going on, but an image says more than a thousand words, so I took a screenie of FF and IE:
Here is the markup:
<div align="center" id="cmContainer" style="background-color: #8CFE70; border: 1px solid #2D9500; border-radius: 4px; width: 400px; height: 161px;">
<span style="color: #2C2C2C; font-family: Arial; font-size: 20px; text-align: center;" />
<font size="24">Look!</font>
<br>
See how different IE renders from FF?
<br>
How can I fix this?
</span>
<br>
<input value="CODE" type="text" size="20" style="font: 20px Arial; color: #000000; background-color: #F3F3F3; border: 1px solid #8D8D8D; width: 300px; border-radius: 2px; text-align: center; margin-top: 0px; padding: 5px 3px 5px 3px; " />
<br>
<input type="button" value="I'm a button!" />
</div>
What can be causing it? I have tried several different stuff with Firebug, but to no avail.
Why does web development have to be this annoying? :)
P.S:Before commenting about my use of Inline Styles, please note that it is how my project requires it. :)
EDIT: By using a CSS Reset, as suggested by Cygal and Christophe, and by applying it only on my objects, here is the result:
Cant really ask for anything better, as easwee so nicely pointed out. ;)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我认为这来自于边框,firefox不计入元素的全局高度,而IE则将边框整合到elem高度中......
所以,它们之间的差异应该是3px,因为最后一个border-bottom不影响其余的部分。
编辑
您是否尝试过使用 CSS 重置,例如:http://meyerweb.com/eric /工具/css/重置/
I think it comes from border that firefox doesn't count in the global height of the element in opposition to IE that integrate borders in elem height...
So, the difference should be 3px between them because the last border-bottom does not affect the rest.
Edit
Have you tried to use a CSS reset like : http://meyerweb.com/eric/tools/css/reset/
问题
没有关于默认元素的默认边距、填充、边框和字体大小的规范。在这里,您的标题边距在 Firefox 中似乎比在 IE9 中更大。请注意,仅解决此特定问题的每个解决方案都不会阻止它出现在其他地方。
解决方案
但是,请记住,如果每个网站在每个浏览器上的显示效果不同,也没关系,而且由于您无法控制的问题(主要是由于网站的大小),它不会显示相同的内容。用户和旧浏览器选择的字体)。另一个解决方案是放弃并使用 em 中的尺寸等技术。 (而不是像素)在适当的时候。 :)
The issue
There is no specification regarding the default margin, padding, border and font-size of default elements. Here, it appears that the margin of your title is bigger in Firefox than in IE9. Note that every solution that only fixes this specific problem will not prevent it from appearing in other places.
The solution
However, remember that it's OK if every website doesn't appear the same on every browser, and that it won't appear the same anyway due to issues you can't control (mainly due the size of the fonts chosen by users and old browsers). Another solution would then be to let go and use techniques like sizes in em. (and not in piexels) when appropriate. :)
尝试在 body 标记上指定边距,这应该允许您准确指定所有浏览器在页面主体上想要的边距
Try specifying the margin on the body tag, that should allow you specify exactly how much of a margin you want on the body of the page for all browsers
font
元素吗? (顺便说一句,没有“24”这样的大小。有效值为 1 到 6。)。span
标记是 XHTML 自闭合标记 ()。 IE 不仅不支持这一点,而且在这种情况下它根本就是错误的。
font
elements, too? (BTW, there is no such size as "24". Valid values are 1 to 6.).span
tag is XHTML self-closed (<span ... />
). Not only doesn't IE support that, it's simply wrong in this case.应该可以解决你的问题,尽管你的 html 很残酷。
Should solve your problem altough your html is brutal.