html - 具有动态页眉、页脚和内容的 CSS 和 html

标签 html css

我正在尝试将页眉、内容和页脚作为动态字段。尝试了很多不同的解决方案,它必须在多个实例中工作。我只需要在内容区域使用滚动条,所以我没有在页脚上使用绝对零。但使用表格布局。

如果您查看代码片段,您会发现内容#wrapper(yellow) 的大小与内容相同。但是当内容(#overflow,黑色)比包装器高时,我无法得到 scoller。

我知道一个小脚本可以解决这个问题,但是只用 CSS 就可以吗??

下面的链接是类似的,但没有好的答案。也许这可能是,如果有可能在内容区域中获得一个工作滚动条。

CSS 100% height layout. Fluid header, footer and content. In IE10 and firefox

<style>
    body {
        margin:0;
        padding:0;
        height:100%;
        width:100%;
        overflow:hidden;
    }
    #wrap {
        height: 150px;
        width: 400px;
        display:table;
        position:absolute;
        text-align:center;
        table-layout:fixed;
        border:1px solid black;
    }
    #header{
        display:table-row;
        border:1px solid red;
        background:green;
    }
    #content{
        height: 100%;
        background:blue;        
        display:table-cell;
    }
    #wrapper{
        width:100%;
        min-height:100%;
        box-sizing:border-box;
        border:10px solid yellow;
        position:relative;
        overflow:scroll;
        display:block;
    }
    #footer{
        width: 100%;        
        display:table-row;
        background:green;
    }
</style>
<body>
    <div id="wrap">
        <div id="header">
            HEADER
        </div>        
        <div id="content">
           <div id="wrapper">
               <div id="overflow" style="height:50px;width:1px;border:10px solid black;"></div>
           </div>
        </div>
        <div id="footer">
            FOOTER
        </div>
    </div>
</body>

最佳答案

你应该为包装元素指定一个高度

#wrapper{
    width:100%;
    /*min-height:100%;*/
    height:100px;
    box-sizing:border-box;
    border:10px solid yellow;
    position:relative;
    overflow:scroll;
    display:block;
}

Here以你的例子工作的 fiddle 。

关于html - 具有动态页眉、页脚和内容的 CSS 和 html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27911824/

相关文章:

html - CSS:将文本框设置为仅显示一个段落

html - 如何在导航栏右侧 float 链接?

javascript - 带按钮的幻灯片图像

javascript - 将线条与线性渐变色标对齐的 Canvas

css - 使用css Grid将未知数量的元素分为两列,但按列顺序列出

javascript - 在执行 ng-repeat 并执行不会反射(reflect)在 html 中的操作时,将范围从 html 绑定(bind)到指令

html - 如何在有一个元素时在 bootstrap 中显示一列,而在有两个元素时显示两列

html - bootstrap 如何在减小浏览器大小时出现滚动条

html - 将图像与另一图像重叠

css - 如何使 flex 组件的底部固定到浏览器底部,但顶部位置动态