Fill the iframe at the bottom of the screen without using tables

I want to display a title with arbitrary content above the iframe, which occupies the rest of the screen. I managed to get this working with tables using the following:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<style>
html, body, iframe, table, tr, td {
  margin: 0; padding: 0;
}
html, body, iframe, table, #content {
  height: 100%; width: 100%;
}
table {
  border-collapse: collapse;
}
iframe {
  border: 0;
}
</style>
</head>
<body>
  <table>
    <tr><td>
      <div id="header">
        <p>some arbitrary stuff in a header</p>
        <p>this is sized dynamically</p>
        <p>it not a fixed size</p>
      </div>
    </td></tr>
    <tr><td id="content">
      <iframe src="http://www.bing.com/search?q=stackoverflow" />
    </td></tr>
  </table>
</body>
</html>

This works in Firefox and Chrome, but not in IE7 (I don't know why). Without using tables, this is the closest I could get:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<style>
html, body {
  margin: 0; padding: 0;
  height: 100%;
}
iframe {
  margin: 0; padding: 0;
  width: 100%;
  border: 0;
}
</style>
</head>
<body>
  <div id="header">
    <p>some arbitrary stuff in a header</p>
    <p>this is sized dynamically</p>
    <p>it not a fixed size</p>
  </div>
  <iframe src="http://www.bing.com/search?q=stackoverflow" />
</body>
</html>

This looks the same in all browsers, but the iframe is too short. If I set its height to 100%, then it would increase to the screen size and two scroll bars would appear (the same as IE7 in the table). I want the iframe to take up all the free space in the browser window, but no more. I would prefer not to resort to Javascript.

+3
5

, CSS-box .

+1

, :

iframe {
    margin: 0; 
    padding: 0;
    width: 100%;
    height: 800px; (Whatever the height of your content is)
    border: 0;
}
+1

Why not just use the old fashion, the usual framework? The point of an iFrame is that it does not expand beyond a regular element.

0
source

Try using the following javascript function

<script language="javascript">
function adjust_iframe(oFrame)
{
    if(!oFrame) return;

    var win_height;
    var frm_height;     

    // Get page height Firefox/IE
    if(window.innerHeight) win_height = window.innerHeight;
 else if(document.body.clientHeight) win_height = document.body.clientHeight;   

    // Dtermine new height
    frm_height = win_height - oFrame.offsetTop - 15; // replace 15 accordingly

    // Set iframe height
    oFrame.style.height = frm_height + "px";
}
</script>   

Note that you will need to call it at some point (e.g. Onload), for example:

<body onload="adjust_iframe(document.getElementById('myiframe'));">
0
source

Source: https://habr.com/ru/post/1709926/


All Articles