简体   繁体   English

Chrome 和 Firefox 中的 HTML 流程不同

[英]HTML flow different in Chrome and Firefox

I have a simple div example with two images one of which has absolute positioning inside the div.我有一个简单的 div 示例,其中包含两个图像,其中一个在 div 内具有绝对定位。

That is my HTML code:那是我的 HTML 代码:

<div style="position: relative;  display: inline; "  >             
<img src="http://www.iphones.ru/wp-content/uploads/2008/09/iphone-girl-10.jpg" / >             
<img style="position: absolute;  top: -400px; left: 100px; z-index: 10" width="32"   height="32"  src="http://4geo.ru/images/other/icon-18plus.png"/>         
</div>   

Try the example http://jsfiddle.net/yQn7W/1/ - you should see the "18+" logo on the face of the girl.试试这个例子http://jsfiddle.net/yQn7W/1/ - 你应该看到女孩脸上的“18+”标志。 It work's fine on both Chrome and Firefox.它在 Chrome 和 Firefox 上都可以正常工作。

But when I make few more divs one after another it seems that Firefox looses HTML flow and leaves "18+" image (which has "position: absolute;" attribute) on the page in the wrong place.但是,当我一个接一个地制作几个 div 时,Firefox 似乎失去了 HTML 流,并在页面上的错误位置留下了“18+”图像(具有“position: absolute;”属性)。

Try the example http://jsfiddle.net/yQn7W/2/试试这个例子http://jsfiddle.net/yQn7W/2/

That's how it looks in the Chrome:这就是它在 Chrome 中的外观:

http://i.stack.imgur.com/3Vhqe.jpg

And that is what Firefox displays:这就是 Firefox 显示的内容:

http://i.stack.imgur.com/qZ4Ee.jpg

This is either to width mismatch or because you haven't properly clearfixed the container.这要么是宽度不匹配,要么是因为您没有正确清除容器。 Since there is no live version of the problem I can't tell which is it, but if you clearfix the container and it doesn't work, you will have to set fixed width for each div, and also set it to float and inline-block, like so:由于没有实时版本的问题,我不知道是哪个问题,但是如果您清除容器并且它不起作用,您将必须为每个 div 设置固定宽度,并将其设置为浮动和内联-block,像这样:

<div style="position: relative; float:left; display: inline-block; width:500px;" >

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

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