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

发布于 2024-12-26 17:13:03 字数 2762 浏览 2 评论 0原文

首先,这是一个链接: http://template1.design.sflueckiger.ch/ page/home.php

我已经尝试了几个小时了,但我似乎找不到解决方案。

页面的结构如下:

body

 <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)。但是,当内容高于屏幕分辨率时,我还需要包装器展开,而不重叠。因此,我需要页脚包装器是相对的。然而,这总是将其直接放置在页面 div 的下方,而不是底部。

有什么想法吗?

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

First of all, here is a link: http://template1.design.sflueckiger.ch/pages/home.php

I have been trying for hours now, but I can't seem to find a solution.

the structure of the page is as follows:

body

 <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>

My problem is that I always want to use 100% height. I managed that fine with the wrapper. The problem now is this:

I want the footer-wrapper to always stay at the bottom (margin:10px) of the wrapper. But, I also need the wrapper to expand when the content gets higher than the screen resolution, without overlapping. Therefore, I need footer-wrapper to be relative. This, however, places it always directly under the page div, instead of the bottom.

Any ideas?

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;
}

Any ideas? Again, the link: http://template1.design.sflueckiger.ch/pages/home.php

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

陌上青苔 2025-01-02 17:13:03

还有一种解决方案:)
将页脚放在页面包装器之外,并且:

#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%;
}

One more solution :)
Put your footer outside the page-wrapper and:

#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%;
}
天冷不及心凉 2025-01-02 17:13:03

这就是您所需要的。

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

#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;
}

Here's what you need.

You want to absolutely-position the footer at the bottom, then add the same amount of padding to the "page".

#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;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文