IE 7、8、9 中 Div 中的垂直间距
我有一个 div 标签,其中包含一些其他元素,如下所示:
<div>
<h3>Text</h3>
<hr/>
<ul>
<li>Text</li>
</ul>
<hr/>
<span>Text</span>
</div>
在 div 中的每个不同元素之间,我为所有元素设置了 0 填充和边距(这反映在开发人员工具中),但是在所有 Internet Explorer 浏览器的每个元素之间都有很大的空间(大约 4-6 像素)。我尝试将 html、正文填充/边距以及 DOM 层次结构中位于其上方的几乎所有其他元素设置为 0,但间距仍然存在。我还尝试最小化 HTML,这样就没有换行符或空格,但这并不能解决问题。
有什么建议可能是什么问题吗?
I have a div tag with a few other elements inside of it, as follows:
<div>
<h3>Text</h3>
<hr/>
<ul>
<li>Text</li>
</ul>
<hr/>
<span>Text</span>
</div>
Between each different element in the div, I have 0 padding and margins set for all of the elements (and it is reflected in the developers tools), however in all Internet Explorer browsers there is a significant space (roughly 4-6 pixels) between each element. I've tried setting the html, body padding/margins to 0, as well as pretty much every other element above it in the DOM hierarchy, however the spacing remains. I've also tried minimizing the HTML so there are no new-lines or spaces, however it does not resolve the problem.
Any suggestions what could be the problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我猜问题是 IE 中的
hr
元素...它不像其他 HTML 元素那样被处理。有很多解决方案......但当你想减少利润时,我无法让其中任何一个发挥作用。话虽这么说……通过反复试验,我设法获得了仅 IE 渲染工作的负边距。无法确定它是否可以在 IE<6、IE7、IE>8 中工作(无法测试)。
最小的 CSS 代码片段:
...我将其限制在 IE8 上,因为网络上说 IE9 中的情况会发生变化...一旦可以测试,我们就会看到:)。请注意,如果您想更改线条的颜色,则需要更改
color
和background-color
的值(取决于所使用的浏览器) : ref)测试并工作于:
(在 WinXP 上)
I guess the issue is the
hr
element in IE... it's not treated like other HTML elements. There are a number of solutions out there... but I couldn't get any of them to work when you want to decrease the margins.That being said... through trial and error I managed to get negative margins for IE only rendering to work. Can't be sure it'll work in IE<6, IE7, IE>8 (can't test).
The minimal CSS code fragment:
... I've limited it to IE8 and less since word on the web is things will change in IE9... we'll see once it can be tested :). Note if you want to change the colour of the line, you'll need to change values of
color
andbackground-color
(depending on the browser one or the other is used: ref)Tested and working in:
(on WinXP)
您看到的空间不是内边距、边距或边框。您会看到每个标签之间都写有“ ”字符。
选项:
1) 将所有元素设置为display:block 或display: inline-block。
2) 一个接一个地写入所有标签,忽略所有空格或回车字符
The space you are seeing is not padding, margin or border. You are seeing the " " character written that exists between each tag.
Options:
1) Set all elements to display:block or display: inline-block.
2) Write all the tags one after the other, dismissing all SPACE or ENTER characters