tags:

views:

877

answers:

3

Hello,

I have a page that holds an iframe:

<div style="position:absolute; width:80%; top:100px; left:10%; z-index:5;">
    <iframe src="www.google.com" />
</div>

Note that the source of the iframe can be from another domain, so I can't change the html in it.

In addition to this ifame I have a menu and some decoration image at the bottom:

<div id="menu" style="position:absolute; width:100%; top:0px; left:0px; z-index:100;">
    ...
</div>

<div id="footer" style="position:absolute; width:100%; bottom:0px; left:0px; z-index:0;">
    ...
</div>

As you can see, I gave z-index to each div, so it should be displayed in that order: the menu on the top, followed by the div with the iframe and at the end the footer image.

What I want is that the iframe (and the div holds it) to have no background (transparent bg color if you like), so the background and the footer image behind it will be visible. Note that I want to change only background color; the text must not change or get opacity.

I managed to get to the bg image and change it (with jquery):

if ($.browser.msie == false) {
    $(document.getElementById("content").contentDocument.body).
                        css('background', "url('transparent.png')");
}
else {
    $(document.getElementById("content").Document.body).
                        css('background', "url('transparent.png')");
}

It works greate on the iframe, but the div that holds it somehow gets a white background.

It won't change if I set the background of the div to this 'transparent.png' image; the div will still save its white background!

If I replace the div with a table, the iframe goes behind the footer image (although it has z-index bigger).

All I want is just to see the footer image behind that iframe...

Please help, I'm quite hopeless... : (

A: 

I tested this and was not able to duplicate the problem. Here's my primary html:

<div style="background:red;">
<div>
    <iframe src="test2.html" />
</div>
</div>

And here's test2.html:

this is a test file

This displays "this is a test file" in an iframe with a red background behind the iframe. Can you post some code to clarify your problem?

Travis
That's not working for me.I tried your solution more then once, both on IE and Firefox; it just put a white backgroung in the iframe.
Orad
Ah, I see. This works in FF3.5, but not in IE8. I'll post something new if I can figure it out.
Travis
A: 

did you try transparent background to the div and that semitransparent background image to the iframe?

TeKapa
It true that now the bg of the 'base' div is visible, but all the text I have in the iframe gets the opacity filter too, what saying that it not visible. I want to change only the background to be transparent.
Orad
+1  A: 

Try:

background: transparent url('transparent.png');

One thing to note, IE6 does not support alpha transparencies for PNGs. You'll want to have an IE specific stylesheet and use an IE only hack for this.


Just to clearify, you arn't trying to get rid of the background color within the iframe itself, but just be able to see the footer and header correct? If this is the case, this should work with an HTML4.01 doctype.

<div style="position:absolute; width:80%; top:100px; left:10%; z-index:5;">
    <iframe style="background-color: transparent;" src="testframe.html" allowtransparency="true"></iframe>
</div>
thismat
Thank you very much, it works finnaly!About your question, I do want to get rid of the background color within the iframe; I've already tried put allowtransparency="true" on the iframe; somehow it not working in IE8.I didn't get what you wrote about IE6; Will the 'transparent.png' work on it?Thanks again!
Orad
The basic gist of it is, alpha transparencies in pngs (like a transparent background) do not render in IE6, there is a hack for this and usually it's a good idea to apply it in an IE only conditional stylesheet. Some information on this here: http://stackoverflow.com/questions/130161/ie6-issues-with-transparent-pngsAlso, if the png is just a 1x1 transparent image, I would use a gif instead since it doesn't suffer the same limitations. Generally when alpha transparencies are used in pngs it's for a more advanced transparency, like a fading gradient.
thismat