Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stretching iframe in HTML5

I have two html files, one contains the other with an iframe, and I want to make this iframe stretch over the full height of the parent html.

So the first html file (which has a red background) look like:

<!DOCTYPE html>
<html>
<body style="background-color: red; margin: 0px; padding: 0px;">
    <iframe src="Blue.html" frameborder="0" scrolling="no"  height="100%" width="100%" />
</body>
</html>

The second (which has a blue background):

<!DOCTYPE html>
<html>    
<body style="background-color: blue;" />
</html>

If all things are correct I expect to see only a blue background, because the iframe should overlap the entire parent page, but I see only a strip of blue, and a whole lot of red..

With the HTML5 doctype <!DOCTYPE html> I cannot seem to be getting the correct result:

With HTML5 DOCTYPE

If I remove the HTML5 doctype I get the result I want. I think this is because it will render the HTML in quirks mode:

Without HTML5 DOCTYPE

I do want the HTML doctype though, so how can I fix this? Thanks for looking!

like image 308
Arcturus Avatar asked Aug 10 '11 13:08

Arcturus


People also ask

How do I stretch an iframe?

Edit the width attribute. You should see the attribute "width=" after the URL in the iframe tag. Edit the width in pixels in quotations (" ") after the "width=" attribute. For example, if you want the width to be 300 pixels, you would enter "width="300px"" after the URL in the tag.

How do I expand an iframe with content?

Answer: Use the contentWindow Property You can use the JavaScript contentWindow property to make an iFrame automatically adjust its height according to the contents inside it, so that no vertical scrollbar will appear.


1 Answers

CSS:

#wrap { position:fixed; left:0; width:100%; top:0; height:100%; }
#iframe { display: block; width:100%; height:100%; }

HTML:

<div id="wrap">
    <iframe src="..." frameborder="0" id="iframe"></iframe>
</div>

Live demo: http://jsfiddle.net/5G5rE/show/

like image 69
Šime Vidas Avatar answered Sep 24 '22 01:09

Šime Vidas