简体   繁体   English

Iframe {height:70%;}在IE 8和Firefox中不起作用

[英]Iframe { height:70%;} not working in IE 8 and Firefox

I have a div contained site design in which i have inserted a iframe to load pages. 我有一个div包含的网站设计,我在其中插入了iframe来加载页面。
header stays at top well
footer stays at bottom very well
content stays at the middle well too

But the iframe isn't stretching to the full height of the container. 但是iframe并没有延伸到容器的整个高度。 i have not mentioned height in pixels in the style

But when i wrote 但是当我写

iframe {
  margin:0;
  padding:0;
  min-height:72%;
  width:100%;
  background-color:#ddd;
}

HTML 的HTML

<div id="container">
  <div id="header"> blah blah </div>
  <div id="content">
      <div id="menu"> some code of menu </div>
      <div id="iframeDiv" class="contentdiv">
         <iframe src="#" id="#" width="100%"></iframe>
      </div>
  </div>
  <div id="footer">blah blah</div>
</div>

CSS 的CSS

html, body {
 margin:0; padding:0; height:100%; width:100%;
}
iframe {
margin:0; padding:0; height:72%; width:100%;
}
#container {
min-height:100%; position:relative; width:100%;
}
#content {
  padding:10px; padding-bottom:30px;
}

I tried writing styles for #iframeDiv but nothing seems to work! 我尝试为#iframeDiv编写样式,但似乎没有任何效果!

it stretched till footer, but this works only in chrome. 它一直延伸到页脚,但这仅适用于Chrome。 ie is not sensing the background color too. 即也没有检测到背景色。 firefox displyed the backgroundcolor but not stretched to 72%. Firefox显示了背景色,但没有拉伸到72%。 how to stretch iframe height to 72% for all browsers. 如何将所有浏览器的iframe高度扩展到72%。 ? 在此处输入图片说明在此处输入图片说明

Check your DOCTYPE of the html page and also you can try to add CSS for the HTML and BODY tag: 检查html页面的DOCTYPE,也可以尝试为HTML和BODY标签添加CSS:

html, body {
    height: 100%;
}

After a long time struggle with iframe, I didnt want to enter the height value explicitly(Px). 在与iframe长期斗争之后,我不想明确输入高度值(Px)。 Since giving it in Px will vary for browsers i used javascript to calculate the consumed height and subtracted from the window height and assigned it to iframe using jquery. 由于在Px中提供它的方式会因浏览器而异,因此我使用javascript计算消耗的高度并从窗口高度中减去,然后使用jquery将其分配给iframe。 Here is what i did. 这是我所做的。

<script type="text/javascript">
 $(document).ready(function() {
  var windowheight = $(window).height();
  var headerheight = $("#header").height();
  var footerheight = $("#footer").height();
  var menuheight = $("#patientMenu").height();
  var frameheight = windowheight - (headerheight+footerheight+menuheight+5);
  //alert(contentheight);
  $('#frameset').css ({
   'height' : contentheight
  });
  });
</script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM