html - 空 block 元素(例如 : <div>s) are rendered differently in Chrome and Firefox; when does it happen and who is right?

标签 html css google-chrome

This page在 Firefox 和 Chrome 中呈现不同。

代码

<p style="border: solid 1px red">Test test</p>
<p style="border: solid 1px red">Test test</p>
<p style="border: solid 1px red">Test test</p>
<div style="margin-bottom: 1em; overflow: auto;"></div>
<p style="border: solid 1px red">Test test</p>
<p style="border: solid 1px red">Test test</p>

<p style="border: solid 1px red">Test test</p>

Firefox、Opera、Internet Explorer

alt text http://koper.wowpanda.net/firefoxr.PNG

Chrome

alt text http://koper.wowpanda.net/chromer.PNG

问题

  1. 谁是对的? Firefox 还是 Chrome?
  2. 具体什么时候发生?例如,如果我添加 padding: 1px 那么 Chrome 也会突然添加底部边距。如果我在 div 内容中添加一些东西(任何东西)也是一样。
  3. 是否有任何 CSS/Javascript hack 可以在不修改 HTML 的情况下使两种浏览器显示相同?

最佳答案

<div style="margin-bottom: 1em; overflow: auto;"></div> 

你需要在这里指定一个高度。

如果您不这样做,chrome 会将其视为空元素并且不会呈现它。而火狐则可以。为避免这种情况,只需添加一个高度属性。像这样:

<div style="margin-bottom: 1em; overflow: auto; height:1px;"></div> 

关于html - 空 block 元素(例如 : <div>s) are rendered differently in Chrome and Firefox; when does it happen and who is right?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2306174/

相关文章:

javascript - 在JQuery弹出关闭按钮上调用JS 'X'

html - 什么是 xml 建议的 url

html - 创建 3 列布局的方法 : Fluid - Fixed - Fluid

jquery - 请解释 jQuery 拖动的这种奇怪行为(在 Chrome 中)

internet-explorer - CORS:成功的 OPTIONS 请求后,Firefox 不会发送 POST 请求...适用于 Chrome 和 IE

html - 如何修复桌面和移动设备上不一致的占位符文本垂直对齐方式?

javascript - 如何在 javaScript 中获取父 div id?

javascript - fieldset 破坏了我在 angularjs-material 中的 flex 布局

html - Office Outlook 客户端中的 Div 宽度不正确

google-chrome - 单独安装和运行,第二个谷歌浏览器