dph6308 2015-12-01 16:35
浏览 119
已采纳

自定义wordpress主题以创建粘性页脚

I want to customize a Wordpress theme (Attitude) in order to add a sticky footer. Unfortunately I am faced by two problems:

  1. If there is not enough content to fill the complete page, a grey gap between the content and the footer appears: Demo

  2. If there is enough content to fill the page, the footer is overlaying the content but I wont the footer to be placed at the end of the page, after the content (if there is enough content to fill the page): Demo

This is my current CSS customizing:

body {
   height:100%;
}
.wrapper {
   min-height:100%;
   position: relative;
}
#site-generator {
   position:fixed;
   bottom:0;
   width:100%;
   background-color: #fff;
   max-width: 1038px;
}

Could you please help me by explaining what I can do to solve my problems mentioned above? Thank you very much.

  • 写回答

1条回答 默认 最新

  • dongmubei7950 2015-12-01 17:24
    关注

    For your Demo 1 example above please add this to your CSS style-sheet:

    html {
        height: 100%;
    }
    

    This will allow your body tag and it's other children to inherit the height of its main ancestor, the html tag. Extending the content to the bottom of the page. Make sure to always have height:100%for both the html and body tag, in order to have it work.

    For your Demo 2 example above add this:

    html {
        height: 100%;
    }
    
    .wrapper {
        padding-bottom: 65px; /* same value as footer .site-generator height */ 
    }
    
    #site-generator {
        position: absolute; /* use absolute instead of fixed */
    }
    

    The reason I use position:absolute instead of position:fixed, is because fixed will always be on top in the same position in the browser viewport.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 写uniapp时遇到的问题
  • ¥15 matlab有限元法求解梁带有若干弹簧质量系统的固有频率
  • ¥15 找一个网络防御专家,外包的
  • ¥100 能不能让两张不同的图片md5值一样,(有尝)
  • ¥15 informer代码训练自己的数据集,改参数怎么改
  • ¥15 请看一下,学校实验要求,我需要具体代码
  • ¥50 pc微信3.6.0.18不能登陆 有偿解决问题
  • ¥20 MATLAB绘制两隐函数曲面的交线
  • ¥15 求TYPCE母转母转接头24PIN线路板图
  • ¥100 国外网络搭建,有偿交流