Sticky Footer for Responsive Site

强颜欢笑 提交于 2019-12-08 02:37:33

Try giving the footer absolute positioning

footer {
position: absolute;
bottom: 0;
}

I've had good success with Ryan Fait's code in the past, but as you mention, it doesn't work well for variable height footers.

The best solution I've found when the footer isn't a fixed height is this Flexbox solution

Flexbox is awesome and forward thinking, so personally I don't mind if you won't have full support for some older browsers.

Working example based on code below. I've used some vendor prefixes so wider browser support but code not so clean

HTML

<body class="Site">
  <header>...</header>
  <main class="Site-content">...</main>
  <footer>...</footer>
</body> 

CSS

.Site {
  display: flex;
  min-height: 100vh;
  flex-direction: column;
}

.Site-content {
  flex: 1;
}

You might want to check out this blog post: http://timothy-long.com/responsive-sticky-footer/

He uses the display: table hack to do it, but the demo page does work fine.

Your other option is using media queries to adapt the footer height as it changes.

You can try this: Modern Clean CSS “Sticky Footer”. Maybe it will help.

Use a footer with: position:absolute; and give it a height, then give margin-bottom: (footer height); to your wrapper.

What about footer { position: fixed; bottom: 0; }

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!