开发者

Elements with no size using position: absolute, inserting blocks above dynamically - what's the correct behaviour?

I have several DIVs with images that are formatt开发者_如何学Goed using position: absolute so they do not interfere with the positioning of the other elements (text) in the DIV.

When an IFRAME with size 728x90 gets created dynamically above those DIVs in the document, Firefox, MSIE8, Opera 11.* and even K-Meleon 1.5.4 move the DIVs as well as the contained images down by 90 pixels. Only Safari (5.0.4) moves down the DIVs, but not the images which are stuck on the position they got before the IFRAME was inserted.

My question: which of the 2 behaviours seen is correct, if any (might be undefined), and why? While the majority of browsers have a helpful behaviour, Safari seems to be doing it "right" by setting the position relative to a parent element with position other than "static" at the time it is added.

(the "fix" is to add position: relative to the DIVs containing the images, but I'd like to know why only Safari needs it)


You must add position:relative; to the container element that you want the position:absolute; elements to be relative to. This is normal, and correct, behavior.

If you don't, they will be relative to <body>, which doesn't seem to be what you want.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜