已知一个div(下称a)宽度700px,现有在a外面包裹一个div(下称b),b插入document.body并设置b的position为relative,a的position为absolute,a的z-index为2,现再向b内插入一个iframe,iframe的position为absolute,z-index为1,怎么才能使得iframe的宽度和高度永远和a一样,即使a的内容发生变化。
我试过将iframe的width和height设置为100%,可是无效。
请用css实现自动调整width和height。js的话每次改变iframe的宽度和高度,实在太烦了。
我试过将iframe的width和height设置为100%,可是无效。
请用css实现自动调整width和height。js的话每次改变iframe的宽度和高度,实在太烦了。
<iframe id="iFrame1" name="iFrame1" width="100%" onload="this.height=iFrame1.document.body.scrollHeight" frameborder="0" src="index.htm"></iframe>
看到了吧,关键就在于onload="this.height=iFrame1.document.body.scrollHeight"!
<option>ie6下能罩住我吗?</option>
</select>
<div style="position:absolute;top:200px;left:200px;">
<div style="width:400px;height:400px;background:#ccc;position:relative;z-index:2;top:0;left:0;"></div>
<iframe frameborder="0" border="0" style="width:100%;height:100%;position:absolute;z-index:1;top:0;left:0;"></iframe>
</div>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style>
body, select, div{margin:0;padding:0;}
</style>
</head>
<body>
<select style="margin:250px 0 0 250px;">
<option>ie6下能罩住我吗?</option>
</select>
<div style="position:absolute;top:200px;left:200px;" id="b">
<div style="width:400px;height:400px;background:#ccc;position:relative;z-index:2;top:0;left:0;" id="a"></div>
<iframe frameborder="0" border="0" style="width:100%;height:100%;position:absolute;z-index:1;top:0;left:0;"></iframe>
</div>
</body>
</html>我就是想要iframe跟随a的宽高度来变化,求解决方案