来自:Default width/height of an IFrame
Demo
” ......我找到了答案在dev-tech-layout mailing list - 这是CSS规范的一部分默认比例为2:1 ...“
”... 默认宽度的300px在CSS规范的最后一段规定,部分上the width of inline replaced elements ...”
否则,如果‘宽’有‘自动’的计算值,但没有的 上述条件得到满足,那么'宽度'的使用值将变成012px300px。如果300px太宽而不适合该设备,则UA应使用具有2:1比例的最大矩形的宽度,而不是适合 设备。
“...的默认高度的为150px在CSS规范的最后一段,节上the height of inline replaced elements定义...”
否则,如果 '高度' 有计算的值为'auto',但上述条件都不满足,则使用的'height'值必须设置为 ,与最大长方形的高度为2:1的比例,高度不为 大于150像素,宽度不大于 设备宽度。
你不给予高度iframe
所以它采取在IE iframe的原始高度试试下面
body {
display: flex;
margin: 0;
height: 100vh;
}
span {
background: green;
}
iframe {
background: tan;
height: 100vh; /* this is required to give it height in IE */
border:0; /* toavoid vertical scroll */
}
这
使用
calc
身高
Demo
,现代浏览器都支持calc
CSS
body {
display: flex;
margin: 0;
height: calc(100vh - 50px);
flex-direction: column;
}
span {
background: green;
height:calc(100vh - 50px);
}
iframe {
background: tan;
height: calc(100vh - 50px); /* this is required to give it height */
border:0; /* to avoid vertical scroll */
}
header {
background: yellow;
height:50px;
}
main {
display: flex;
flex: 1;
}
Final Demo
使用一些的jQuery来达到同样的
jQuery的
// If you put your code at the bottom of the page to avoid needing`$(document).ready`, it gets even simpler:
$(window).on('resize', function() {
var demoheight = $(window).height() - $('header').height();
$("body, iframe, span").css("height", demoheight);
}).trigger('resize');
// Another way to do that same thing
// $(document).ready(myfunction);
// $(window).on('resize', myfunction);
// function myfunction() {
// var demoheight = $(window).height() - $('header').height();
// $("body, iframe, span").css("height", demoheight);
// }
// Another technique is to`.trigger()`one event inside the other:
// $(window).on('resize', function() {
// var demoheight = $(window).height() - $('header').height();
// $("body, iframe, span").css("height", demoheight);
// });
// $(document).ready(function() {
// $(window).trigger('resize');
// });
CSS
body {
display: flex;
margin: 0;
flex-direction: column;
}
span {
background: green;
}
iframe {
background: tan;
border:0;
}
header {
background: yellow;
}
main {
display: flex;
flex: 1;
}
使用javascript获取可用的宽度和高度,并设置iframe与给定的值。如果它也应该在窗口大小调整时工作,请使用eventlistener来更改iframe的宽度/高度。 –