首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >CSS - Height: 100% vs min-height: 100%;

CSS - Height: 100% vs min-height: 100%;
EN

Stack Overflow用户
提问于 2012-12-23 05:28:00
回答 1查看 909关注 0票数 4

因此,在我的代码中,我有一个粘性页脚。粘性页脚的#wrap容器的min-height100%。但是在min-height中,你不能在包装div中的对象上使用height:100%

所以我添加了height:100%,但当窗口高度太小时,它会使页脚滚动到换行div中的内容上,从而扰乱布局。

有人有解决这个问题的办法吗?

代码语言:javascript
复制
<div id="wrap">
    <div id="main">
        <div id="content">

        </div>
    </div>
    <div class="clearfooter"></div>
</div>
<div id="footer">

</div>

CSS:

代码语言:javascript
复制
*{
    padding: 0px;
    margin: 0px;
}
html, body {
    height: 100%;
}
body{
    color: #FFF;
    background-image:url('../images/black_denim.png');
}
#wrap {
    min-height: 100%;
    margin-bottom: -200px;
    position: relative;
}
#topBanner{
    width: 200px;
    margin: 0px auto;
}
.clearfooter {
    height: 200px;
    clear: both;
}
/* footer */
#footer { 
    position: relative;
    height: 200px;
    width: 100%;
    min-width: 960px;
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-12-23 05:44:19

如果你所需要的只是一个粘性的页脚,不会遮盖任何正文的内容,那么只需要给页脚一个固定的位置,并让正文的底部填充等于页脚的高度。

代码语言:javascript
复制
body{ 
    padding-bottom:200px;
}

#footer { 
    position: fixed;
    bottom:0;
    height: 200px;
    width: 100%;
}

编辑:

如果你担心的是,在非常小的屏幕上,固定的页脚覆盖了大部分屏幕,那么除了使用css媒体查询或javascript动态隐藏页脚之外,没有其他解决办法。

许多移动浏览器不支持固定位置,正是因为它们覆盖了大部分屏幕的问题。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14006720

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档