简体   繁体   English

div高度未扩展到页面底部

[英]Div height is not extending to bottom of page

I have a page layout for a website I'm developing that goes something like this: 我正在开发的网站的页面布局如下所示:

-------------------------------------Top Bar-------------------------------------
|                                                                               |
---------------------------------------------------------------------------------
--------Content (Has a dark filter that goes over the main background image)-----
------------ Main Content---------------------------|-------------SideBar--------
|                                                   |                           |
|                                                   |                           |
|                                                   |                           |
|                                                   |                           |
|                                                   |                           |
|                                                   |                           |
|                                                   |                           |
---------------------------------------------------------------------------------

The in my page is usually a photo that, for design purposes, I need to apply a dark filter. 我页面中的通常是一张照片,出于设计目的,我需要应用深色滤镜。 So I create a .content class that serves that purpose, and everything (except for the top bar) goes inside it. 因此,我创建了一个用于该目的的.content类,所有内容(顶部栏除外)都位于其中。

The problem I have is that, when the content in the .main-content container exceeds the page height, the filter does not go to the bottom of the page. 我的问题是,当.main-content容器中的内容超过页面高度时,筛选器不会到达页面底部。 I have the .content height at 100%, as well as the body and the html tags. 我的内容高度为100%,还有正文和html标签。

html {
    font-size: 16px;
    height:100%;
    overflow:auto;
}
body {
    font-size: 62.5%;
    /*10px = 1em*/
    line-height: 1.4;
    width:100%;
    height: 100%;
    min-height: 100%;
    overflow: auto;
}
.top-bar {
    width:100%;
    height:58px;
    position:fixed;
    top:0px;
    z-index: 5;
}
.top-bar.user {
    background-color:rgba(0, 0, 0, 1);
    font-size: 1.2em;
}
.content {
    display: block;
    margin-top: 58px;
    /* = top bar height*/
    width: 100%;
    height: 100%;
    min-height: 100%;
    position: absolute;
    background-color: rgba(0, 0, 0, 0.3);
    -webkit-background-size: cover;
    -moz-background-size: cover;
    -o-background-size: cover;
    background-size: cover;
}
.main-content {
    float: left;
    width: 75%;
    height: 100%;
}
.sidebar {
    position: fixed;
    right: 0;
    width: 25%;
    height: 100%;
}

I tried to create the issue here: http://jsfiddle.net/apGgd/3/ 我试图在此处创建问题: http : //jsfiddle.net/apGgd/3/

Has you can see, as the table expands, the filter (the grey background) does not go along it. 您是否已看到,随着表格的扩展,过滤器(灰色背景)并未随之移动。 However if you remove the 'height:100%' from the .content, the issue goes away. 但是,如果您从.content中删除“ height:100%”,则问题将消失。

The reason it works is when you remove the height:100% is because you don't need to explicitly declare it. 它起作用的原因是当您删除height:100%是因为您不需要显式声明它。 What you want is height:auto; min-height:100%; 你想要的是height:auto; min-height:100%; height:auto; min-height:100%; . This will ensure that the height is at least 100%, but will fill the table as needed, which I think is the behavior you want. 这将确保高度至少为100%,但会根据需要填充表格,我认为这是您想要的行为。

Updated jsFiddle 更新了jsFiddle

you just delete height:100%; 您只需删除身高:100%; from the .content section and add an overflow:show;(if the previous is not worked) 从.content部分开始,并添加一个overflow:show;(如果以前的方法不起作用)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM