<header id="topNavBar" class="topNavBar">
  <nav class="topNavWrap">
    <h1 class="main-heading"><img class="logo" src="https://picsum.photos/id/1015/50/50" alt="logo" width="50" height="50"> <span>Site Heading</span></h1>
    <button id="toggle" class="toggle"><b>Menu</b></button>
    <ul class="topNavMain">
      <li><a href="index.html">Home</a></li>
      <li><a href="portfolio.html">Gallery</a></li>
      <li><a href="about.html">About</a></li>
      <li><a href="contact.html">Contact</a></li>
    </ul>
  </nav>
</header>
<main class="main-content">
  <div class="wrap">
    <p>Start content to scroll</p>
    <p>Content to scroll</p>
    <p>Content to scroll</p>
    <p>Content to scroll</p>
    <p>Content to scroll</p>
    <p>Content to scroll</p>
    <p>Content to scroll</p>
    <p>Content to scroll</p>
    <p>Content to scroll</p>
    <p>Content to scroll</p>
    <p>Content to scroll</p>
    <p>Content to scroll</p>
    <p>Content to scroll</p>
    <p>Content to scroll</p>
    <p>Content to scroll</p>
    <p>Content to scroll</p>
    <p>Content to scroll</p>
    <p>Content to scroll</p>
    <p>Content to scroll</p>
    <p>Content to scroll</p>
    <p>Content to scroll</p>
    <p>Content to scroll</p>
    <p>Content to scroll</p>
    <p>Content to scroll</p>
    <p>Content to scroll</p>
    <p>Content to scroll</p>
    <p>Content to scroll</p>
    <p>Content to scroll</p>
    <p>Content to scroll</p>
    <p>Content to scroll</p>
    <p>Content to scroll</p>
    <p>Content to scroll</p>
    <p>Content to scroll</p>
    <p>Content to scroll</p>
    <p>Content to scroll</p>
    <p>Content to scroll</p>
    <p>Content to scroll</p>
  </div>
</main>
<foote class="main-footer">
  <div class="wrap">
    Footer
  </div>
</foote>
html,
body {
  margin: 0;
  padding: 0;
}
html {
  height: 100%;
}
body {
  min-height: 100%;
  display: flex;
  flex-direction: column;
}
.wrap {
  max-width: 1280px;
  margin: auto;
}
.topNavBar {
  position: fixed;
  position: -webkit-sticky;
  position: sticky;
  top: 0;
  left: 0;
  width: 100%;
  z-index: 1001;
  background: #898989;
  box-shadow: 0px 0px 9px rgba(0, 0, 0, 0.3);
}
.topNavWrap {
  display: flex;
  align-items: center;
  max-width: 1280px;
  padding: 10px;
  margin: 0 auto;
  color: #fff;
}
.topNavMain {
  list-style: none;
  margin: 0 0 0 auto;
  padding: 0;
  display: flex;
  flex: 1 0 0;
  justify-content: flex-end;
}
.topNavMain li {
  margin: 0 0 0 4rem;
}
.topNavMain a {
  color: #fff;
  text-decoration: none;
  padding: 10px;
  font-size: 1.5rem;
}
.topNavMain a:hover {
  background: #c6c6c6;
  color: #000;
}
.main-heading {
  margin: 0;
  display: flex;
  align-items: center;
}
.logo {
  margin-right: 1rem;
  border: 1px solid #000;
}
.main-content {
  flex: 1 0 0;
  background: rgba(0, 0, 0, 0.3);
  padding: 0 10px;
}
.main-footer {
  padding: 10px;
  background: #000;
  color: #fff;
  text-align: center;
}

/* hamburger menu */
.toggle {
  display: none;
  position: absolute;
  z-index: 99;
  top: 50%;
  left: 15px;
  background: transparent;
  padding: 0;
  margin: -10px 0 0 0;
  cursor: pointer;
  outline: none;
  width: 25px;
  height: 18px;
  border: none;
  border-top: 2px solid #fff;
  border-bottom: 2px solid #fff;
  text-decoration: none;
  color: #fff;
  outline: 0;
}
.toggle b {
  display: none;
}
.toggle:before,
.toggle:after {
  content: "";
  display: block;
  width: 25px;
  height: 2px;
  top: 6px;
  left: 0;
  background: #fff;
  position: absolute;
}
.toggle,
.toggle:before,
.toggle:after {
  transition: all 0.3s ease;
  transform: rotate(0deg);
}
.open .toggle {
  border-color: transparent;
}
.open .toggle:before {
  transform: rotate(45deg);
}
.open .toggle:after {
  transform: rotate(-45deg);
}

@media screen and (max-width: 900px) {
  .topNavMain li {
    margin: 0 0 0 2rem;
  }
  .topNavMain a {
    font-size: 1.3rem;
  }
}

@media screen and (max-width: 768px) {
  .toggle {
    display: block;
  }
  .main-heading {
    flex: 1 0 0;
    justify-content: center;
    margin: 0 50px;
  }
  .main-heading .logo {
    width: 40px;
    height: auto;
  }

  /* redo nav for smaller screen*/
  .topNavMain {
    position: absolute;
    display: block;
    background: #666;
    top: 0%;
    width: 100%;
    left: -999rem;
    text-align: center;
    transition: top 0.5s ease, left 0s 0.5s, opacity 0.5s ease;
    opacity: 0;
    border-top: 1px solid #000;
  }
  .open .topNavMain {
    left: 0;
    opacity: 1;
    top: 100%;
    transition: top 0.5s ease, left 0s 0s, opacity 0.5s ease;
  }

  .topNavMain li {
    display: block;
    font-size: 1rem;
    text-align: center;
    margin: 0;
  }
  .topNavMain li a {
    display: block;
    padding: 10px;
    color: #f1d9b3;
    text-decoration: none;
  }
  .topNavMain li a:hover {
    background: red;
  }
  .topNavMain li {
    text-align: center;
    border-bottom: 1px solid #000;
  }
}
(function (d) {
  "use strict";

  const toggleParent = d.getElementById("topNavBar");
  const myToggle = d.getElementById("toggle");
  myToggle.addEventListener(
    "click",
    function () {
      toggleParent.classList.toggle("open");
    },
    false
  );
})(document);
Run Pen

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.