Search code examples
htmlcssinternet-explorerflexboxcss-calc

HTML Flex layout looks different in Internet Explorer


I'm trying to get a simple flex layout to work the same in IE11 as it does in Chrome.

In Chrome it appears like this: enter image description here

However in IE11 it appears like this: enter image description here

Here is the code :

html,
body {
  margin: 2px 0 0 0;
  padding: 0;
}

.wrap {
  display: flex;
  min-height: calc( 100vh - 8px);
  flex-direction: column;
  max-width: 1200px;
  margin: auto;
  border: 1px solid #222222;
}

.main {
  flex: 1 1 auto;
  display: flex;
}

header {
  background: green;
  padding: 10px;
}

#footer {
  background: green;
  padding: 10px;
}

.sidebar {
  background: blue;
  flex: 0 0 135px;
  padding: 10px;
}

.content {
  background: yellow;
  padding: 10px;
  flex: 1 1 auto;
}

@media screen and (max-width:680px) {
  .sidebar {
    flex: 0;
    order: 2
  }
  .main {
    flex-direction: column;
  }
}
<body translate="no">


  <div class="wrap">


    <header>

      <div class="header-inner-left">
      </div>

      <div class="header-inner">
      </div>

    </header>

    <main class="main">


      <div class="sidebar">

      </div>



      <div class="content">


      </div>


    </main>



    <div id="footer">
      <div class='footerleft'>

      </div>
      <div class='footerright'>

      </div>
      <div style="clear: both;"></div>
    </div>



  </div>

</body>

That shows the HTML & CSS. Is there anyway to make this look the same.

If I set .wrap so it uses:

height: calc( 100vh -  8px );

Then the loading page looks correct, but I need the ability for the content to grown beyond the .wrap correctly so set min-height: calc( 100vh - 8px );

Is there any way to do this ? Thanks


Solution

  • Here's an idea that may work for you:

    body {
      display: flex;
    }
    
    .wrap {
      min-height: 100vh;
      flex-grow: 1;
      display: flex;
      flex-direction: column;
      max-width: 1200px;
      border: 1px solid #222222;
    }
    
    .main {
      flex: 1 1 auto;
      display: flex;
    }
    
    header {
      background: green;
      flex: 0 0 25px;
    }
    
    #footer {
      background: green;
      flex: 0 0 25px;
    }
    
    .sidebar {
      background: blue;
      flex: 0 0 135px;
      padding: 10px;
    }
    
    .content {
      background: yellow;
      padding: 10px;
      flex: 1 1 auto;
    }
    
    body {
      margin: 0;
    }
    
    * {
      box-sizing: border-box;
    }
    <div class="wrap">
      <header>
        <div class="header-inner-left"></div>
        <div class="header-inner"></div>
      </header>
      <main class="main">
        <div class="sidebar"></div>
        <div class="content"></div>
      </main>
      <div id="footer">
        <div class='footerleft'></div>
        <div class='footerright'></div>
        <div style="clear: both;"></div>
      </div>
    </div>