cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - Activehtmlicon-personicon-teamoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

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 id="main-header">
  <nav role='navigation'>
    <ul id="main-nav">
      <li><a href="#">Home</a></li>
      <li><a href="#">About</a></li>
      <li><a href="#">Clients</a></li>
      <li><a href="#">Contact Us</a></li>
    </ul>
  </nav>  
</header>
<section id="main-content">
  <p>Etiam auctor lorem eu consectetur vehicula. Etiam convallis vehicula ornare. Integer vel varius nulla. Nam tempor condimentum ex, non euismod arcu vulputate et. Integer malesuada tortor quis lectus congue tempus. Sed et dolor nulla. Etiam ac lectus tempor, dictum elit sed, vestibulum libero.

  <p>Nunc tempus dictum luctus. Curabitur ipsum dui, elementum eu ultricies quis, dapibus molestie ante. Mauris commodo dignissim est, pharetra lobortis velit aliquet eget. Praesent vel laoreet tellus. Nulla sit amet elit interdum, facilisis leo in, rutrum purus. Nam semper nisi lacus, quis consequat enim condimentum id. Mauris enim eros, euismod non mauris sed, imperdiet cursus eros. Proin purus libero, elementum eu turpis nec, molestie vehicula nisl.</p>

  <p>Vivamus sodales orci vitae semper malesuada. Vivamus eros risus, rutrum eu suscipit vitae, laoreet ut dui. Cras et tincidunt ligula, a porttitor elit. Nam sollicitudin, odio id suscipit blandit, justo ligula facilisis quam, eu egestas felis est eget leo. Donec non consequat lacus. Donec vestibulum malesuada massa eu porta. Vivamus vestibulum tortor enim, id suscipit ligula scelerisque sit amet. Quisque iaculis luctus facilisis. Aliquam sollicitudin justo nisi, pellentesque convallis nibh fermentum eget.</p>
  
  <p>Cras aliquam ex sit amet est fermentum pellentesque. Praesent semper, elit quis elementum tempor, turpis arcu tincidunt enim, in consequat nisl nulla ut neque. Vestibulum vehicula augue orci, nec faucibus est maximus egestas. In aliquam, ipsum eleifend commodo commodo, est sapien porta ex, nec dapibus nibh leo sed purus. Praesent convallis nunc libero, ac imperdiet elit dapibus ut. Fusce consectetur felis pretium nulla gravida, non vehicula nulla consequat. Ut eleifend dictum dolor, ac sollicitudin eros feugiat et.</p>
</section>
            
          
!
            
              * {
  margin: 0;
  padding: 0;
  font-family: georgia, times, serif;
}

#main-header {
  background-color: grey;
  padding: 20px;
  margin-bottom: 20px;
}

#main-nav li,
#main-nav li a {
  text-decoration: none;
  text-transform: uppercase;
  color: white;
  display: inline;
  margin: 0;
  padding: 0 10px;
}

#main-content {
  padding: 0 20px;
  max-width: 500px;
}

p { margin-bottom: 15px; }

/* Here is the simple magic */

#main-header.sticky {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  background-color: rgba(0,0,0,0.8);
}
            
          
!
            
              $(window).scroll(function() {
  if ($(this).scrollTop() > 1){  
    $('#main-header').addClass("sticky");
  }
  else{
    $('#main-header').removeClass("sticky");
  }
});
            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console