如何使iframe的宽度和高度与其父级div相同? [英] How to make width and height of iframe same as its parent div?

查看:2186
本文介绍了如何使iframe的宽度和高度与其父级div相同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个div内的iframe。我希望iframe的大小恰好与其父div的大小相同。我使用以下代码来设置iframe的宽度和高度。

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'">

但iframe的宽度与div不一样,同时显示水平和垂直滚动条。 p>

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

推荐答案

您有很多错别字。

正确的标记应该是例如:

a correct markup should be like:

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

如果这个框架已经有一个ID,为什么不把它放在 CSS 像这样(来自单独的样式表文件):

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%; 
}

HTML $ b

and HTML

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

介意滚动& frameborder iframe 属性,而不是 style 属性。

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

这篇关于如何使iframe的宽度和高度与其父级div相同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆