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.

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

报告相同问题?

悬赏问题

  • ¥20 数学建模,尽量用matlab回答,论文格式
  • ¥15 昨天挂载了一下u盘,然后拔了
  • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题
  • ¥20 易康econgnition精度验证
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能