I cannot get z-index working on a iframe that contains a pdf file with IE8. It works with Google Chrome.
Example (JSFiddle):
HTML
<div id="div-text">
<div id="shouldBeOnTop">my text that should be on top</div>
</div>
<div id="div-frame">
<iframe src="http://legallo1.free.fr/french/CV_JLG.pdf" width="200" height="200"/>
</div>
CSS
#div-text{
position:relative;
left:210px;
top:20px
}
#shouldBeOnTop{
position:relative;
right:60px;
background-color:red;
width:100px;
z-index:2;
}
#div-frame{
position:relative;
z-index:1;
}
Update: Matthew Wise has a really clever alternative solution which you should consider—especially if you’re having trouble with my approach or dislike ugly hacks!
There is a way to cover windowed elements in IE with other elements, but you’re not going to like it.
Background: windowed and windowless elements
Legacy IE categorises elements into two types: windowed and windowless.
Regular elements like
divandinputare windowless. They are rendered by the browser itself in a single MSHTML plane and respect each other’s z-order.Elements rendered outside of MSHTML are windowed; for example,
select(rendered by the OS) and ActiveX controls. They respect each other’s z-order, but occupy a separate MSHTML plane that is painted on top of all windowless elements.The only exception is
iframe. In IE 5,iframewas a windowed element. This was changed in IE 5.5; it is now a windowless element, but for backwards compatibility reasons it will still draw over windowed elements with a lower z-indexIn other words:
iframerespects z-index for both windowed and windowless elements. If you position aniframeover a windowed element, any windowless elements positioned over theiframewill be visible!What this means
The PDF will always be painted on top of the regular page content—like
selectelements were until IE 7. The fix is to position anotheriframebetween your content and the PDF.Demo
jsFiddle: http://jsfiddle.net/Jordan/gDuCE/
Code
HTML:
CSS:
Support
This has been tested and should work in IE 7–9. If you feel persnickety about it showing up in the DOM for other browsers, you can add it with JavaScript or wrap it in an IE-only conditional comment: