<header>
  <div id="main" class="duplicate">
    <ul class="nav">
      <li>
        <a href="javascript://" title="Home">
          <span class="icon-stack">
            <i class="icon-circle icon-stack-base"></i>
            <i class="icon-home icon-light"></i>
          </span>
          <span class="text">Home</span>
        </a>
      </li>
      <li>
        <a href="javascript://" title="About">
          <span class="icon-stack">
            <i class="icon-circle icon-stack-base"></i>
            <i class="icon-leaf icon-light"></i>
          </span>
          <span class="text">About</span>
        </a>
      </li>
      <li>
        <a href="javascript://" title="Contact">
          <span class="icon-stack">
            <i class="icon-circle icon-stack-base"></i>
            <i class="icon-phone icon-light"></i>
          </span>
          <span class="text">Contact</span>
        </a>
      </li>
    </ul>
  </div>
  <div id="stickyContent"></div>
</header>

<div class="contentWrap">
<div class="content">
  <h1>Sticky Header Visual Trick</h1>
  <p>Sticky headers seem to be very popular now, but most of them rely on scroll events. One bad thing about relying on the scrolling event is that mobile safari doesn't execute the function that is attached to the event until after the browser is done scrolling. There is also the <code>position:sticky</code>, but it isn't widely supported yet.</p>
  <p>What you see here is a little visual trick (hack) to do something similar to what you might see in a sticky header. This requires two headers in the markup. This is probably really bad for SEO. Anyways, I have the JS duplicate the menu markup so I don't have to write it twice. The main header is <code>position:relative</code> while the sticky header is <code>position:fixed</code>. The main one has a higher z-index that the sticky header.</p>
  <p>I find that the interaction looks better when the main header is much bigger than the sticky one. Also, having more space between the main header and the content is better. Also, the page needs to be long enough so that the main header clears when you scroll all the way.</p>
</div>
</div>
code {
  background-color: #ddd;
}
.contentWrap {
  padding: 2em;
}
.content {
  width: 650px;
  margin: 0 auto;
  min-height: 1250px;
  line-height: 1.5em;
}
h1 {
  font-size: 2em;
  line-height: 2em;
}

/*** Styles for the main header ***/
	#main {
	  background-color: #eee;
	  position: relative;
	  z-index: 1001;
	}
  ul.nav {
    padding-left: 0;
  }
	ul.nav {
	  width: 650px;
	  margin: 0 auto;
	  overflow: hidden;
	}
	ul.nav li {
	  float: left;
	  list-style: none;
	  margin: .5em .5em .5em 0;
	  padding: .5em .5em .5em 0;
	  font-size: 1.5em;
	}
	ul.nav li a {
	  text-decoration: none;
	  color: #ccc;
	}
	ul.nav li a:hover {
	  color: #E0461B;
	  transition: color 400ms ease-out;
	}
	
/*** Styles for the sticky header ***/
  #stickyContent {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    background-color: #E0461B;
  }
  #stickyContent ul.nav li {
    font-size: 1em;
  }
  #stickyContent ul.nav a {
    color: #612717;
  }
  #stickyContent ul.nav .text{
    display: none;
  }
document.getElementById('stickyContent').innerHTML = document.getElementById('main').innerHTML;

External CSS

  1. https://netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.min.css

External JavaScript

This Pen doesn't use any external JavaScript resources.