首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >CSS设计:保持相对位置,但停留在包含div的底部

CSS设计:保持相对位置,但停留在包含div的底部
EN

Stack Overflow用户
提问于 2012-01-13 04:47:57
回答 2查看 13.6K关注 0票数 1

首先,这里有一个链接:http://template1.design.sflueckiger.ch/pages/home.php

我已经试了好几个小时了,但我似乎找不到解决办法。

页面结构如下:

正文

代码语言:javascript
复制
 <div: container - streches the window to all sides at 100%>
 <div: wrapper - keeps the content in the middle>
 <div: page - contains the actual content>
 <div: footer-wrapper - this one contains 3 footer-boxes>

我的问题是我总是想使用100%的高度。我用包装器做到了这一点。现在的问题是:

我希望页脚包装器始终位于包装器的底部(margin:10px)。但是,我还需要包装器在内容高于屏幕分辨率时进行扩展,而不会重叠。因此,我需要footer-wrapper是相对的。然而,这总是将它放在页面div的正下方,而不是底部。

有什么想法吗?

代码语言:javascript
复制
body{
    width: 100%;
    height:100%;
    margin: 0;
    padding: 0;
    background:whitesmoke;
}

#top-bar{
    background-color: #F0F0F0 ;
    top: 0px ;
    left: 0px;
    height: 40px ;
    position:fixed;
    width: 100%;
    border-bottom: 1px solid black ;
    z-index: 1000; 
    /*Position of content*/
    text-align:center;
    box-shadow:0px 0px 10px 3px #555;
}
#container{
    position: absolute;
    text-align: center; 
    width: 100%;
    height: 100%;
    left: 0px;
    right: 0px;
    top: 0px;
    bottom: 0px;

}

#top-bar p{
    margin-top:10px;
}

#page-wrapper{
    min-height:100%;
    width:982px;
    margin:0 auto;
    border:1px solid #555;
    background:#999;
    box-shadow:0px 0px 10px 3px #555;
    position:relative;
}

#page{
    width:960px;
    height:300px;
    margin:50px 10px 10px 10px;
    border:1px solid white;
    background:whitesmoke;

}

#page p{
    padding:10px;
}

#footer-wrapper{
    position:relative;
    bottom:0;
    width:962px;
    height:202px;
    margin:30px 10px 10px 10px !important;  
}

#footer-wrapper p{
    padding-left:10px;
}
#footer-1{
    height:200px;
    width:312px;
    margin:0px 10px 0px 0px;
    float:left;
    background:whitesmoke;
    border:1px solid white;
    border-radius:0px 0px 5px 5px;;
    -webkit-border-radius:0px 0px 5px 5px;
    -moz-border-radius:0px 0px 5px 5px;

}
#footer-2{
    height:200px;
    width:312px;
    margin:0px 10px 0px 0px;
    float:left;
    background:whitesmoke;
    border:1px solid white;
    border-radius:0px 0px 5px 5px;;
    -webkit-border-radius:0px 0px 5px 5px;
    -moz-border-radius:0px 0px 5px 5px;
}
#footer-3{
    height:200px;
    width:312px;
    margin:0px 0px 0px 0px;
    float:left;
    background:whitesmoke;
    border:1px solid white;
    border-radius:0px 0px 5px 5px;;
    -webkit-border-radius:0px 0px 5px 5px;
    -moz-border-radius:0px 0px 5px 5px;
}

有什么想法吗?同样,链接:http://template1.design.sflueckiger.ch/pages/home.php

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-01-13 05:15:35

还有一个解决方案:)将你的页脚放在页面包装器之外,然后:

代码语言:javascript
复制
#footer-wrapper {
    width: 962px;
    margin: -202px auto 0;
    height: 202px;
    position: relative;
}

#page {
    width: 962px;
    margin: 0 auto;
    min-height: 100%;
    height: auto !important;
    height: 100%;
}
票数 4
EN

Stack Overflow用户

发布于 2012-01-13 05:02:22

这就是你所需要的。

你想绝对定位页脚在底部,然后添加相同数量的填充到“页面”。

代码语言:javascript
复制
#footer-wrapper {
  bottom: 0;
  height: 202px;
  margin: 30px 10px 10px !important;
  position: absolute;
  width: 962px;
}

#page {
  background: none repeat scroll 0 0 whitesmoke;
  border: 1px solid white;
  height: 300px;
  margin: 50px 10px 320px;
  width: 960px;
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8842064

复制
相关文章

相似问题

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