css iframe自适应高度(iframe的高度可以随内容的多少而变化吗)

本文目录
- iframe的高度可以随内容的多少而变化吗
- iframe的高度怎么根据内容的多少来决定它具体的高度请写清注释、谢谢
- 求助!!iframe 自适应高度 隐藏滚动条
- iframe跨域自适应高度
- 有iframe让父页面自动调整高度
iframe的高度可以随内容的多少而变化吗
iframe的高度可以随内容的多少而变化,解决方法如下:
1、首先在文件夹里创建两个html文件,一个“index”一个“iframe”。
2、然后在index中添加一个iframe标签,直接嵌入iframe页面。
3、接着在iframe网页中添加了两个固定高度的div内容。
4、浏览器打开index页面,发现iframe部分有滚动条,需要滚动显示页面。
5、现在在index页面的iframe标签再添加如下的属性。再次打开index页面iframe已经高度自适应了。
iframe的高度怎么根据内容的多少来决定它具体的高度请写清注释、谢谢
实现同域iframe高度自适应,可使用偶写的代码实现: 【aaaaa_1.html Code】《iframe id=“pa_frame“ src=“aaaaa_2.html“ frameborder=“0“ scrolling=“no“ width=“100%“》《/iframe》
《script type=“text/javascript“》
window.onload=function (){
var pa_frame=document.getElementById(’pa_frame’);
pa_frame.style.height=pa_frame.contentWindow.document.body.scrollHeight+’px’;
}
《/script》 【aaaaa_2.html Code】《style type=“text/css“》
body{margin:0;padding:0;}
《/style》
《p》1《/p》
《p》2《/p》
《p》3《/p》
《p》4《/p》
《p》5《/p》
《p》6《/p》
《p》7《/p》
《p》8《/p》
《p》9《/p》
《p》10《/p》
求助!!iframe 自适应高度 隐藏滚动条
你可以用Jquery控制iframe的宽和高。获取窗口可视部分的宽高设置给iframe
//文档加载完成时
$(document).ready(function(e) {
$(“iframe“).height($(window).height());
$(“iframe“).width($(window).width());
});
//为了适应用户取消了浏览器全屏时的效果,你还需加一个窗口改变时的事件
$(window).resize(function(){
$(“iframe“).height($(window).height());
$(“iframe“).width($(window).width());
});
iframe跨域自适应高度
《!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN“ “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd“》
《html xmlns=“http://www.w3.org/1999/xhtml“》
《head》
《meta http-equiv=“Content-Type“ content=“text/html; charset=gb2312“ /》
《title》无标题文档《/title》
《style type=“text/css“》
body {
background-attachment:fixed;
margin: 0px;
}
#bottomNav {
z-index:999;
position:fixed;/*FireFox */
top: 0px;/*FireFox */
left:0;
right:0;
width:100%;
_position:absolute; /* for IE6 */
_top: expression(documentElement.scrollTop + documentElement.clientHeight-this.offsetHeight); /* for IE6 */
overflow:visible;
}
.nav{
width:960px;
margin-right: auto;
margin-left: auto;
}
.text{
width:930px;
background-color: #CCCCCC;
float: left;
}
.link{
width:30px;
background-color: #CCCCCC;
float: right;
text-align: center;
text-decoration: none;
}
#ifr{
width:100%;
}
《/style》
《script type=“text/javascript“》
function showHideDIV(){
var doc = document.getElementById(“Maple“);
doc.style.display =
(doc.style.display == “none“?“block“:“none“);
}
《/script》
《/head》
《body》
《div id=“bottomNav“》
《div class=“nav“》
《div id=“Maple“ class=“text“》固定漂浮物在此处O(∩_∩)O~《/div》《div class=“link“》《a href=“javascript:void(0);“ onclick=“showHideDIV()“》显《/a》《/div》
《/div》
《/div》
《iframe src=“http://www.youku.com“ scrolling=“no“ frameborder=“0“ id=“ifr“》《/iframe》
《/body》
《/html》
《!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN“ “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd“》
《html xmlns=“http://www.w3.org/1999/xhtml“》
《head》
《meta http-equiv=“Content-Type“ content=“text/html; charset=gb2312“ /》
《title》无标题文档《/title》
《style type=“text/css“》
body {
background-attachment:fixed;
margin: 0px;
}
#bottomNav {
z-index:999;
position:fixed;/*FireFox */
top: 0px;/*FireFox */
left:0;
right:0;
width:100%;
_position:absolute; /* for IE6 */
_top: expression(documentElement.scrollTop + documentElement.clientHeight-this.offsetHeight); /* for IE6 */
overflow:visible;
}
.nav{
width:960px;
margin-right: auto;
margin-left: auto;
}
.text{
width:930px;
background-color: #CCCCCC;
float: left;
}
.link{
width:30px;
background-color: #CCCCCC;
float: right;
text-align: center;
text-decoration: none;
}
#ifr{
width:100%;
}
《/style》
《script type=“text/javascript“》
function showHideDIV(){
var doc = document.getElementById(“Maple“);
doc.style.display =
(doc.style.display == “none“?“block“:“none“);
}
《/script》
《/head》
《body》
《div id=“bottomNav“》
《div class=“nav“》
《div id=“Maple“ class=“text“》固定漂浮物在此处O(∩_∩)O~《/div》《div class=“link“》《a href=“javascript:void(0);“ onclick=“showHideDIV()“》显《/a》《/div》
《/div》
《/div》
《iframe src=“http://www.youku.com“ scrolling=“no“ frameborder=“0“ id=“ifr“》《/iframe》
《/body》
《/html》
《!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN“ “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd“》
《html xmlns=“http://www.w3.org/1999/xhtml“》
《head》
《meta http-equiv=“Content-Type“ content=“text/html; charset=gb2312“ /》
《title》无标题文档《/title》
《style type=“text/css“》
body {
background-attachment:fixed;
margin: 0px;
}
#bottomNav {
z-index:999;
position:fixed;/*FireFox */
top: 0px;/*FireFox */
left:0;
right:0;
width:100%;
_position:absolute; /* for IE6 */
_top: expression(documentElement.scrollTop + documentElement.clientHeight-this.offsetHeight); /* for IE6 */
overflow:visible;
}
.nav{
width:960px;
margin-right: auto;
margin-left: auto;
}
.text{
width:930px;
background-color: #CCCCCC;
float: left;
}
.link{
width:30px;
background-color: #CCCCCC;
float: right;
text-align: center;
text-decoration: none;
}
#ifr{
width:100%;
}
《/style》
《script type=“text/javascript“》
function showHideDIV(){
var doc = document.getElementById(“Maple“);
doc.style.display =
(doc.style.display == “none“?“block“:“none“);
}
《/script》
《/head》
《body》
《div id=“bottomNav“》
《div class=“nav“》
《div id=“Maple“ class=“text“》固定漂浮物在此处O(∩_∩)O~《/div》《div class=“link“》《a href=“javascript:void(0);“ onclick=“showHideDIV()“》显《/a》《/div》
《/div》
《/div》
《iframe src=“http://www.youku.com“ scrolling=“no“ frameborder=“0“ id=“ifr“》《/iframe》
《/body》
《/html》
《!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN“ “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd“》
《html xmlns=“http://www.w3.org/1999/xhtml“》
《head》
《meta http-equiv=“Content-Type“ content=“text/html; charset=gb2312“ /》
《title》无标题文档《/title》
《style type=“text/css“》
body {
background-attachment:fixed;
margin: 0px;
}
#bottomNav {
z-index:999;
position:fixed;/*FireFox */
top: 0px;/*FireFox */
left:0;
right:0;
width:100%;
_position:absolute; /* for IE6 */
_top: expression(documentElement.scrollTop + documentElement.clientHeight-this.offsetHeight); /* for IE6 */
overflow:visible;
}
.nav{
width:960px;
margin-right: auto;
margin-left: auto;
}
.text{
width:930px;
background-color: #CCCCCC;
float: left;
}
.link{
width:30px;
background-color: #CCCCCC;
float: right;
text-align: center;
text-decoration: none;
}
#ifr{
width:100%;
}
《/style》
《script type=“text/javascript“》
function showHideDIV(){
var doc = document.getElementById(“Maple“);
doc.style.display =
(doc.style.display == “none“?“block“:“none“);
}
《/script》
《/head》
《body》
《div id=“bottomNav“》
《div class=“nav“》
《div id=“Maple“ class=“text“》固定漂浮物在此处O(∩_∩)O~《/div》《div class=“link“》《a href=“javascript:void(0);“ onclick=“showHideDIV()“》显《/a》《/div》
《/div》
《/div》
《iframe src=“http://www.youku.com“ scrolling=“no“ frameborder=“0“ id=“ifr“》《/iframe》
《/body》
《/html》
有iframe让父页面自动调整高度
一般来说,父页面的高度是自动的,iframe高度再大,父页面也会自动适应的
除非楼主你的父页面设置了高度以及overflow:hidden之类的样式
另外iframe里面的内容超过1000px的话,而且iframe设置了没有滚动条的话,就没有滚动条了【这是后话】
或者楼主给出部分代码看看

更多文章:
another time(another time和other time的区别)
2026年10月11日 05:00








