JSFiddle - React, Tailwind, and code Playground

by Andy Kuds

HTML

<section>
<header>header</header>


 
  <main>content
    <div>
      This div get a height when in landscape to show scroll in section
    </div>  
  </main>
<footer>footer</footer>



<nav>navigation
    <div>
      This div get a height when in landscape to show scroll in nav
    </div>
  </nav>
</section>

CSS

html, body {
  margin:0;
}
header, footer, main, nav {
  margin: 5px;
  padding: 5px;
  border-radius: 5px;
  min-height: 120px;
  border: 1px solid #eebb55;
  background: #ffeebb;
}
footer {
  order: 2;
}
nav {
  order: 1;
}
section {
  display: flex;
  flex-direction: column;
}

@media only screen and (orientation: landscape) {

  main div {
    height: 400px;
    border: 1px dashed red;
  }
  nav div {
    height: 800px;
    border: 1px dashed red;
  }

  body.landscape {
    display: flex;
  }
  section {
    display: block;
    width: calc(60% - 10px);         /*  10px is for the margin  */
    box-sizing: border-box;
    max-height: calc(100vh - 20px);
    overflow: auto;
  }
  nav {
    width: calc(40% - 10px);         /*  10px is for the margin  */
    box-sizing: border-box;
    max-height: calc(100vh - 20px);
    overflow: auto;
  }
}

JavaScript

(function(d,timeout) {
  window.addEventListener("load", function() {
    resizeHandler();
  }, false);

  window.addEventListener("resize", function () {
    if (!timeout) {
      timeout = setTimeout(function() {
        timeout = null;
        // do resize stuff
        resizeHandler();        
      }, 66);
    }
  }, false);
  function resizeHandler() {
        if (window.innerHeight < window.innerWidth) {
          if (!(d.body.classList.contains('landscape'))) {
            d.body.classList.add('landscape');
            d.body.appendChild(d.querySelector('nav'));      
          }
        } else {
          if (d.body.classList.contains('landscape')) {
            d.body.classList.remove('landscape')
            d.querySelector('section').appendChild(d.querySelector('nav'));      
          }        
        }  
  }
}(document));