1

我需要一个带有标题的页面和一个从其他站点显示的 iframe。这是我使用的:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> 
<head> 
    <style type="text/css"> 
    *{margin:0;padding:0} 
    html, body {height:100%;width:100%;overflow:hidden} 
    table {height:100%;width:100%;table-layout:static;border-collapse:collapse} 
    iframe {height:100%;width:100%} 
    .header2 {border-bottom:1px solid #000;height:90px;} 
    .content2 {height:100%} 
</style> 
</head> 
<body>
<table>
<tr>
    <td class="header2">
    asdasdasdasd
    </td>
</tr>
<tr>
    <td class="content2">
        <iframe src="http://www.w3schools.com" scrolling="auto" frameborder="1" />
    </td>
</tr>
</table>
</body>
</html>

问题是这段代码没有显示完整的页脚(由于页眉部分,90 像素超出页面)。

4

2 回答 2

6

桌子伤害了我的眼睛。position: absolute为此被严重低估。试试这个布局:

<!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>
        <title>Test Layout</title>
        <style type="text/css">
            body, html
            {
                margin: 0; padding: 0; height: 100%; overflow: hidden;
            }
            #header
            {
                position:absolute; left: 0; top: 0; right: 0; height: 90px; background: red;
            }
            #content
            {
                position:absolute; left: 0; right: 0; bottom: 0; top: 90px; background: blue; height: expression(document.body.clientHeight-90);
            }
        </style>
    </head>
    <body>
        <div id="header">
            Test content
        </div>
        <div id="content">
            <iframe width="100%" height="100%" src="startdoc.html" />
        </div>
    </body>
</html>

一直正确渲染到 IE6 以及在我用最少的黑客测试过的每个浏览器上的奖励积分 :)

于 2012-10-19T12:04:28.123 回答
0

Make your header absolute positioned, so it overlays over the iframe, like so:

<table>
<tr style="position:absolute;top:5px">
    <td class="header2">
    asdasdasdasd
    </td>
</tr>
<tr>
    <td class="content2">
        <iframe src="http://www.yahoo.com" scrolling="auto" frameborder="1" />
    </td>
</tr>
</table>​​​
于 2012-10-19T12:05:17.953 回答