7

我已经搜索了1个多小时没有成功。是否有模拟框架集的纯 CSS 方式?我的意思是,真的模仿它。我发现了一些有趣的东西,您可以在其中固定顶部和底部块,但内容的滚动条是常规的浏览器主体滚动条。我需要的是一个仅用于内容块的滚动条,就像框架集一样。

我可以通过将 overflow: auto 分配给我的内容区域 div 并设置固定高度来使其工作。但问题是如果不使用 javascript,我不知道客户端浏览器窗口的大小。而且我不想为此使用javascript。我也不能使用百分比作为高度,因为我的顶块有一个固定的高度。下部块是应该根据浏览器窗口高度扩展或收缩的块。任何帮助表示赞赏。谢谢!

4

3 回答 3

1

这样的事情怎么样?

HTML

<div id="header">
    <img src="logo.gif" alt="logo" />
    <h1 class="tagline">Oh em gee</h1>
</div>
<div id="content">
    <div id="content-offset">
        <p>This will be 100% of the screen height, BUT the content offset will have a top pixel margin which allows for your header. Set this to the pixel value of your header height.</p>
    </div>
</div>

CSS

body, html {
    margin: 0; padding: 0;
    height: 100%;
}
#header {
   height: 120px;
   position: fixed;
   top: 0;
   background: red;
   width: 100%;
}

#content {
    height: 100%;
    position: absolute;
    top: 0;
}
#content-offset {
    margin-top: 120px;
    background: aqua;
    height: 100%;
    width: 100%;
    position: fixed;
    overflow: auto;
}
于 2010-08-08T05:06:41.880 回答
1

Makro 的答案很接近,但效果不佳。内容与标题重叠。

直截了当,您希望将其position: fixed;用于标题,而不是用于您的内容。这也使包装器变得多余。这是一个基本的启动示例,您可以复制'n'粘贴'n'运行它。

<!DOCTYPE html>
<html lang="en">
    <head>
        <title>SO question 3433129</title>
        <style>
            body { 
                margin: 0;
                background: aqua;
            }
            #header {
                position: fixed;
                height: 120px;
                width: 100%;
                background: pink;
            }
            #content {
                padding-top: 120px; /* Should be the same as #header height */
            }
        </style>
    </head>
    <body>
        <div id="header">
            <h1>Header</h1>
        </div>
        <div id="content">
            <p>Start of content.</p>
            <p><br><br><br><br><br><br><br><br><br><br><br><br><br><br></p>
            <p><br><br><br><br><br><br><br><br><br><br><br><br><br><br></p>
            <p><br><br><br><br><br><br><br><br><br><br><br><br><br><br></p>
            <p>End of content.</p>
        </div>
    </body>
</html>
于 2010-08-08T05:22:12.857 回答
0

不,我认为您将不得不使用 javascript 来获取窗口大小,除非您将顶部块设置为固定的 % 大小,例如将顶部块设置为 10%,底部块设置为 90%。

于 2010-08-08T05:01:16.453 回答