【问题标题】:How to make a page expand with content HTML/CSS?如何使用内容 HTML/CSS 使页面扩展?
【发布时间】:2014-05-13 22:49:28
【问题描述】:

基本上我的页面由

组成

a) 一个主 div,#main b)标题,#header c) 一个 div,#contain d) 页脚,#footer

页面内容进入contain div。

代码:

#main{
    position: absolute;
    top: 0px;
    left: 15%;
    width: 70%;
    min-height: 100%;
    border: 1px solid black;

    }

    #header{
    position: relative;
    top: 0px;
    left: 0px;
    width: 100%;
    height: 100px;
    }

    #contain{
    position: relative;
    top: 40px;
    padding-top: 20px;
    left: 5%;
    width: 90%;
    min-height: 600px;
    border:1px solid green;

    } 


    #footer{
    width: 100%;
    height: 5%;
    bottom: 0;
    border-top: 1px dotted black;
    position: absolute;
    }

如您所见,包含 div 的最小高度为 600 像素。 当页面填满时,它会正确扩展,但会扩展 越过页脚并超出“主”div。

显然我希望页脚保持在主页面的底部 次,但主要只是不根据包含 div 展开 即使它的最小高度是页面的 100%。

【问题讨论】:

  • 你不能给#main的min-height一个百分比。
  • top: 40px; 正在将您的#contain 推到其他元素之外。

标签: html css sticky-footer


【解决方案1】:

将您的#bottom div 设置为相对静态高度,例如 50px 或 100px,然后删除 #main min-height。

http://jsfiddle.net/JH2q9/3/

#main {
    position: absolute;
    top: 0px;
    left: 15%;
    width: 70%;
    border: 1px solid black;
}
#contain {
    position: relative;
    left: 5%;
    width: 90%;
    border: 1px solid green;
    /* min-height: 1000px; yes, its work if you need that */
} 
#footer {
    width: 100%;
    height: 50px;
    bottom: 0;
    border-top: 1px dotted black;
    margin-top: 10px;
    position: relative;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-10-14
    • 1970-01-01
    • 2020-03-07
    • 1970-01-01
    • 2020-01-05
    • 1970-01-01
    • 2015-04-23
    • 1970-01-01
    相关资源
    最近更新 更多