根据 iframe 内加载的内容自动调整 div/iframe 的大小
我在网上看到了很多相互矛盾的信息,我认为这里的人们比绝大多数其他地方的人更了解。
是否可以有一个带有 iframe 的 div 自动调整宽度(可能还包括高度)->WITHOUT<- 使用 javascript.. 还需要具有跨浏览器功能(浏览器像 lynx 和 ie5 根本不是问题)。
几天来我一直在网上修改并遵循各种人的建议,但我仍然没有看到我的 div 和 iframe 将其宽度限制为 iframe 中加载的任何数据(只是随机信息表)。
这是我拥有的一些 css 和相关的 html,你可以看出它已经经历了一些没有 width:auto; 的修订。高度:自动等
div#topleftdiv
{
float: left;
width: 25%;
height: auto;
}
iframe#topleftframe
{
background-color: transparent;
-moz-opacity: .00;
filter: alpha(opacity=00);
}
div#toprightdiv
{
float: right;
width: 25%;
height: auto;
}
iframe#toprightframe
{
background-color: transparent;
-moz-opacity: .00;
filter: alpha(opacity=00);
}
div#topmiddlediv
{
float: left;
width: 49%;
height: auto;
text-align: center;
align: center;
margin-left: auto;
margin-right: auto;
}
iframe#topmiddleframe
{
width: 100%;
height: 40em;
text-align: center;
align: center;
margin-left: auto;
margin-right: auto;
-moz-border-radius: 15px;
border-radius: 15px;
}
div#bottomdiv
{
clear: both;
}
<div id="topleftdiv" scrolling="no">
<iframe id="topleftframe" name="topleftframe" scrolling="no" allowtransparency="true" frameBorder="0">
</iframe>
</div>
<div id="toprightdiv" scrolling="no">
<iframe id="toprightframe" name="toprightframe" scrolling="no" allowtransparency="true" frameBorder="0">
</iframe>
</div>
<div id="topmiddlediv" scrolling="no">
<iframe id="topmiddleframe" name="topmiddleframe" scrolling="no" allowtransparency="true" frameborder="0" noresize>
</iframe>
</div>
I see alot of contradictory information on this online and I figured people here would know better than the vast majority of other places.
Is it possible to have an div with an iframe inside of it autosize the width (and possibly height) ->WITHOUT<- the use of javascript.. also it needs to be crossbrowser capable (browsers like lynx and ie5 are not a concern at all).
I have been tinkering and following various peoples suggestions online in regards to this for days but I still do not see my div and iframe limit their width to whatever data is loading in the iframe (just tables of random info).
Here is some of the css I have and the associated html, as you can tell it has since gone through some revisions that do not have width:auto; height:auto etc.
div#topleftdiv
{
float: left;
width: 25%;
height: auto;
}
iframe#topleftframe
{
background-color: transparent;
-moz-opacity: .00;
filter: alpha(opacity=00);
}
div#toprightdiv
{
float: right;
width: 25%;
height: auto;
}
iframe#toprightframe
{
background-color: transparent;
-moz-opacity: .00;
filter: alpha(opacity=00);
}
div#topmiddlediv
{
float: left;
width: 49%;
height: auto;
text-align: center;
align: center;
margin-left: auto;
margin-right: auto;
}
iframe#topmiddleframe
{
width: 100%;
height: 40em;
text-align: center;
align: center;
margin-left: auto;
margin-right: auto;
-moz-border-radius: 15px;
border-radius: 15px;
}
div#bottomdiv
{
clear: both;
}
<div id="topleftdiv" scrolling="no">
<iframe id="topleftframe" name="topleftframe" scrolling="no" allowtransparency="true" frameBorder="0">
</iframe>
</div>
<div id="toprightdiv" scrolling="no">
<iframe id="toprightframe" name="toprightframe" scrolling="no" allowtransparency="true" frameBorder="0">
</iframe>
</div>
<div id="topmiddlediv" scrolling="no">
<iframe id="topmiddleframe" name="topmiddleframe" scrolling="no" allowtransparency="true" frameborder="0" noresize>
</iframe>
</div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不,这是不可能的。您需要 JavaScript 将帧大小传达回父窗口。
基本的 JavaScript,如果您改变主意的话:
来自 iFrame:
No, it's not possible. You need JavaScript to communicate the frame size back to the parent window.
The basic JavaScript, should you change your mind:
from the iFrame: