如何在 IE11 中使用 flexbox 制作粘性页脚? [英] How to make a sticky footer using flexbox in IE11?

查看:19
本文介绍了如何在 IE11 中使用 flexbox 制作粘性页脚?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 flexbox 进行简单的设计,但是我在使用 IE11 时遇到了问题.基本上,我想要一个仅在内容不够高的情况下才粘在底部的页脚.我对 Chrome 这样做没有问题:

I'm trying to make a simple design with flexbox but I'm having trouble with IE11. Basically, I want a footer that sticks to the bottom only if the content is not high enough. I have no issue doing that with Chrome like this:

*,
*:after,
*:before {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  padding: 0;
}

body {
  display: flex;
  flex-direction: column;
}

main {
  flex: 1;
}

<header>
  Header
</header>
<main>
  <p>Main</p>
  <p>Main</p>
  <p>Main</p>
  <p>Main</p>
  <p>Main</p>
</main>
<footer>
  Footer
</footer>

只需玩玩

main

Just play with the number of <p>main</p> to see the wrong behaviour with IE11.

有没有不用 JavaScript 就能实现的方法?

Is there a way to achieve this without JavaScript?

推荐答案

IE 有一个 min-height 错误,需要 display: flex 在 flex 列容器父项上,在这种情况下 html

IE has a min-height bug and needs display: flex on the flex column containers parent, in this case the html

小提琴演示

像这样更新你的 CSS

Update your CSS like this

*,
*:after,
*:before {
  box-sizing: border-box;
}
html, body {
  margin: 0;
  display: flex;
}
body {
  flex-direction: column;
  min-height: 100vh;
}
main {
  flex-grow: 1;
}

<header>
  Header
</header>
<main>
  <p>Main</p>
  <p>Main</p>
  <p>Main</p>
  <p>Main</p>
  <p>Main</p>
</main>
<footer>
  Footer
</footer>

这篇关于如何在 IE11 中使用 flexbox 制作粘性页脚?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆