cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              <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;
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console