CSS - 使 div 占用所有可用空间

标签 css html css-position

全部,

我有一个页面应该只占用浏览器中的可用屏幕空间。

我有一个“顶栏”和一个“底栏”,它们都固定在页面的顶部和底部。我想要一个 div,它将消耗(占用)上述两个栏之间的剩余空间。

enter image description here

重要的是中间的 div 不与顶部和底部的栏重叠。这完全可以使用 CSS 还是我需要使用 js。

此外,如果我确实使用 js,考虑到浏览器在 js 代码之前首先加载 CSS,那么使用 js 进行中心定位如何解决上述问题?

非常感谢,

最佳答案

您可以使用相对绝对 位置。举个例子:

CSS

   html,body,#wrapper {
        height:100%;
        margin:0;
        padding:0;
    }
    #wrapper {
        position:relative;
    }

    #top, #middle, #bottom {
        position:absolute;
    }

    #top {
        height:50px;
        width:100%;
        background:grey;
    }
    #middle {
        top:50px;
        bottom:50px;
        width:100%;
        background:black;
    }
    #bottom {
        bottom:0;
        height:50px;
        width:100%;
        background:grey;
    }

html

<div id="wrapper">
    <div id="top"></div>
    <div id="middle"></div>
    <div id="bottom"></div>
</div>

演示: http://jsfiddle.net/jz4rb/4

关于CSS - 使 div 占用所有可用空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5776367/

相关文章:

HTML <p> 和 <span> - 元素背景颜色不起作用

html - Bootstrap 3 : Having problems modifying the navbar

html - 为什么我的日历图标没有出现在表格单元格中?

html - CSS - 绝对位置,如何忽略父级的左侧和顶部

javascript - 具有平滑滚动的 Jquery 航路点

css - 推特 Bootstrap : Icon rendered differently in IE vs Firefox

javascript - 在一页滚动站点的 html 中更改 fancybox 关闭按钮

jquery - 如何正确定位css元素?

html - 调整浏览器大小时绝对位置错误

html - 如何使用 css 中的 flex box 实现带有 Font Awesome 图标的联系页面,比如我的图像