Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How Do I Fix A Flexbox Sticky Footer In IE11

I have created a sticky footer using flexbox. It works in all browsers apart from IE11.

Codepen

html {
  box-sizing: border-box;
}

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

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

.Page-header {
  background: blue;
}

.Page-footer {
  background: green;
}

.Page-body {
  background: red;
  flex: 1;
}
<div class="Page">
  <header class="Page-header">
    HEADER
  </header>
  <div class="Page-body">
    BODY
  </div>
  <footer class="Page-footer">
    FOOTER
  </footer>
</div>

Why is it breaking in IE11 and how can I fix it?

like image 296
Undistraction Avatar asked Aug 05 '15 14:08

Undistraction


People also ask

How do I fix the bottom footer on flex?

Just add margin-top: auto; to the footer. That will cause it to stick to the bottom of its container.

What is a sticky footer?

A sticky footer pattern is one where the footer of your page "sticks" to the bottom of the viewport in cases where the content is shorter than the viewport height.


2 Answers

Try

flex: 1 0 auto;

for content block

like image 158
Timofey Orischenko Avatar answered Oct 20 '22 04:10

Timofey Orischenko


The problem is that in IE11 flexbox won't honour min-height, so the flex box collapses to the height of its contents.

You can fix it by wrapping your flexbox inside another flexbox that also has flex-direction: column. You will also need to set flex: 1 on your original flexbox. For some reason this forces the nested flexbox to honour any its min-height.

Codepen

html {
  box-sizing: border-box;
}

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

.Wrapper {
  display: flex;
  flex-direction: column;
}

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

.Page-header {
  background: blue;
}

.Page-footer {
  background: green;
}

.Page-body {
  background: red;
  flex: 1;
}
<div class="Wrapper">
  <div class="Page">
    <header class="Page-header">
      HEADER
    </header>
    <div class="Page-body">
      BODY
    </div>
    <footer class="Page-footer">
      FOOTER
    </footer>
  </div>
</div>
like image 37
Undistraction Avatar answered Oct 20 '22 05:10

Undistraction