Search code examples
htmlcssinternet-explorerflexbox

Flexbox not working in Internet Explorer 11


This piece of code works fine in Firefox, Chrome and Edge, but it does not work properly in IE11 because of flex model, apparently. How can I fix it?

This is how it looks in Firefox

enter image description here

This is how it looks in IE11

enter image description here

body * {
  box-sizing: border-box;
}
html {
  height: 100%;
}
body {
  min-height: 100%;
  display: flex;
  flex-flow: column;
  margin: 0;
}
main {
  flex: 1;
  display: flex;
}
header,
footer {
  background: #7092BF;
  border: solid;
  width: 100%;
}
section {
  border: solid;
  background: #9AD9EA;
  flex: 1
}
aside {
  border: solid;
  width: 150px;
  background: #3E48CC
}
<header>
  <p>header
</header>
<main>
  <aside>
    <p>aside
    <p>aside
  </aside>
  <section>
    <p>content
    <p>content
    <p>content
    <p>content
  </section>
</main>
<footer>
  <p>footer
  <p>footer
</footer>


Solution

  • According to Flexbugs:

    In IE 10-11, min-height declarations on flex containers work to size the containers themselves, but their flex item children do not seem to know the size of their parents. They act as if no height has been set at all.

    Here are a couple of workarounds:

    1. Always fill the viewport + scrollable <aside> and <section>:

    html {
      height: 100%;
    }
    
    body {
      display: flex;
      flex-direction: column;
      height: 100%;
      margin: 0;
    }
    
    header,
    footer {
      background: #7092bf;
    }
    
    main {
      min-height: 0; /* added 2021*/
      flex: 1;
      display: flex;
    }
    
    aside, section {
      overflow: auto;
    }
    
    aside {
      flex: 0 0 150px;
      background: #3e48cc;
    }
    
    section {
      flex: 1;
      background: #9ad9ea;
    }
    <header>
      <p>header</p>
    </header>
    
    <main>
      <aside>
        <p>aside</p>
      </aside>
      <section>
        <p>content</p>
        <p>content</p>
        <p>content</p>
        <p>content</p>
        <p>content</p>
        <p>content</p>
        <p>content</p>
        <p>content</p>
        <p>content</p>
        <p>content</p>
      </section>
    </main>
    
    <footer>
      <p>footer</p>
    </footer>

    2. Fill the viewport initially + normal page scroll with more content:

    html {
      height: 100%;
    }
    
    body {
      display: flex;
      flex-direction: column;
      height: 100%;
      margin: 0;
    }
    
    header,
    footer {
      background: #7092bf;
    }
    
    main {
      flex: 1 0 auto;
      display: flex;
    }
    
    aside {
      flex: 0 0 150px;
      background: #3e48cc;
    }
    
    section {
      flex: 1;
      background: #9ad9ea;
    }
    <header>
      <p>header</p>
    </header>
    
    <main>
      <aside>
        <p>aside</p>
      </aside>
      <section>
        <p>content</p>
        <p>content</p>
        <p>content</p>
        <p>content</p>
        <p>content</p>
        <p>content</p>
        <p>content</p>
        <p>content</p>
        <p>content</p>
        <p>content</p>
      </section>
    </main>
    
    <footer>
      <p>footer</p>
    </footer>