Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Iframe embedded with 100% height in a div has strange bottom-margin

Tags:

html

css

I want to wrap an iframe element with height 100% and width 100% into a div with fixed size.

I tried it like this:

<div style="height: 410px; width: 480px; border: 1px solid black; overflow: auto;">
    <iframe src="" style="border: none; background: blue;" height="100%" width="100%"></iframe>
</div> 

With older doctypes it works perfectly, but as soon as I add the HTML5 doctype <!DOCTYPE html> there is a disturbing scrollbar which makes it possible to move the whole iframe element up and down inside the surrounding div and if you scroll completely down there is a strange space, I can't explain.

When I remove the overflow: auto; property from the div-style it works too, but this can't be the solution.

The thing I don't understand is why there is this strange space/margin below the iframe element?

Here is a demo you can try yourself: http://jsfiddle.net/tmuecksch/b5jgn/

I tried it in Safari 7.0 and Firefox 23.0.1.

like image 856
tmuecksch Avatar asked Sep 08 '13 14:09

tmuecksch


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 set the iframe margin in HTML?

HTML | <iframe> marginwidth Attribute The HTML <iframe> margin width Attribute is used to specifies the left and right margin of the content in an Iframe Element. Attribute Values: pixels: It contains the value i.e pixel which specifies the right and left a margin of the content in an Iframe Element.

Can you put an iframe in a div?

By using an <iframe> within a <div> , it is possible to include external web content in most any web document. This method serves as an excellent alternative to actual frames, which are not as flexible and definitely not as popular.


2 Answers

Add display:block for your iframe element – without that, it is rendered as an inline box, and therefor space is left for the under-lengths of glyphs like g, p, f etc. of (hypothetical) text that might be displayed on the same line.

See fiddle: http://jsfiddle.net/b5jgn/2/

(vertical-align:bottom for the iframe would also work.)

like image 79
CBroe Avatar answered Nov 11 '22 15:11

CBroe


iframe { vertical-align:bottom; }

or

iframe { display:block; }
like image 37
Rameez Avatar answered Nov 11 '22 15:11

Rameez