Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make width and height of iframe same as its parent div?

Tags:

I have a iframe inside a div. I want the size of iframe to be exactly the size of its parent div. I used following code to set the width and height of iframe.

<iframe src="./myPage.aspx" id="myIframe"      style="position: relative;              height: 100%;              width: 100%'              scrolling='no'              frameborder='0'"> 

But width of iframe is not same as div, also both horizontal and vertical scrollbar are displayed.

like image 210
Rohita Khatiwada Avatar asked Sep 12 '13 13:09

Rohita Khatiwada


People also ask

How do I set the iframe height to fit content?

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.

How can I set my iframe height width and 100%?

To get the iframe to properly use 100% the parent needs to be 100%. In newer doctypes the html and body tag are not automatically 100%. When I added height:100% for html and body then it worked flawlessly.

Can an iframe be in a div?

Approach 1: For adding additional div's in an iframe, you need to use a wrapper div, that wraps the contents of your intended div and the iframe into one unit. This way you can display the contents of your div along with the iframe embedding to the document/webpage.


1 Answers

you have a lot of typos.

a correct markup should be like:

<iframe src="./myPage.aspx" id="myIframe" scrolling="no" frameborder="0"     style="position: relative; height: 100%; width: 100%;"> ... </iframe> 

also, if this frame already has an ID, why don't you put this in CSS like this (from a separate stylesheet file):

#myIframe {     position: relative;     height: 100%;     width: 100%;  } 

and HTML

<iframe src="./myPage.aspx" id="myIframe" scrolling="no" frameborder="0" > ... </iframe> 

mind that scrolling & frameborder are iframe attribute, not style attribute.

like image 89
avrahamcool Avatar answered Sep 19 '22 10:09

avrahamcool