【问题标题】:can NOTmake my footer stick AND provide a scroll bar for content不能让我的页脚粘贴并为内容提供滚动条
【发布时间】:2012-09-17 21:16:12
【问题描述】:

我已经用谷歌搜索并阅读了关于制作“粘性页脚”的所有内容,但由于某种原因,我无法让它正常工作。这是我的 html/body div、主要内容 div 和我的页脚 div 的 CSS 代码:

body, html {
margin-top: 5px;
margin-bottom: 5px;
padding: 0px;
height: 100%;
font-family: Cooper Black, Copperplate Gothic Bold, Britannic Bold, Garamond, Arial;
font-size: 1em;
color: #666666;
background-color: #EDF5FC;}

#main {
position: relative;
top: 380px;
width: 90%;
height:100%;
min-height: 100%;
margin: 0px 5% -20px 5%;
z-index: 10;
padding-top: 0px;
padding-bottom: 20px;
overflow:scroll;}

#footer {
clear:both;
position:fixed;
margin-left:auto;
margin-right:auto;
margin-bottom:0px;
margin-top: -20px; /* negative value of footer height */
width:98%;
height:20px;
padding-top:3px;
background: #0E28B1;
text-align: center;
color: #ffffff;
font-size: .7em;
font-weight:bold;
z-index:1;}

我的页脚 div 在我的主 div 之外(网站的主要内容在主 div 内,然后我将其关闭并拥有页脚 div。)我可以通过使用固定位置和边距使其粘在底部-bottom: 0,但是我的内容没有滚动条。

这根本不起作用。我做错了什么?

【问题讨论】:

    标签: html css sticky-footer


    【解决方案1】:

    我终于找到了适合我的解决方案!我找到了这个网站:http://boagworld.com/dev/fixed-footers-without-javascript/ 并稍微修改了代码,以便我的页脚文本很好地垂直和水平居中,并在主(内容)div 中添加了我的页面顶部高度。我想如果没有第三个“#Wrapper” div 包含所有内容,这将无法正常工作 - 所以现在这是我的包装器,主要和页脚 css,用于那些有同样问题的人:

    #wrapper {
    display: block; 
    position: absolute; 
    min-height: 100%; }
    
    #main {
    display: block;
    top: 400px;
    width: 90%; 
    margin-bottom: 20px; }
    
    #footer {
    position: fixed; 
    display: block; 
    bottom: 0; 
    height: 20px; 
    background: #0E28B1;
    width: 98%;
    margin-right:auto;
    margin-left:auto;
    font-size: .7em;
    font-weight:bold;
    font-family: Cooper Black, Copperplate Gothic Bold, Britannic Bold, Garamond, Arial;
    color: #ffffff;
    text-align:center;
    z-index:2;
    padding-top:3px;}
    

    我必须在页脚 2 而不是 1 中设置 z-index 以将页脚保持在内容文本的顶部。但现在它起作用了。在找到此解决方案之前,我已经搜索了很多网站(包括这个),所以我希望这对某人有所帮助。

    【讨论】:

      猜你喜欢
      • 2013-01-13
      • 2012-08-20
      • 1970-01-01
      • 2016-04-21
      • 2016-07-11
      • 2014-07-02
      • 2017-03-17
      • 2016-01-04
      • 1970-01-01
      相关资源
      最近更新 更多