Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <html>
  <body>
    <div id="announcement"><div class="container">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur posuere nisl in nunc euismod, sit amet porttitor ex accumsan. Quisque nec magna nisi. Integer porta odio quis felis mattis, vitae bibendum lorem maximus. Fusce luctus neque orci, ut pellentesque velit auctor eu. Proin iaculis nunc sed fringilla semper. Vestibulum ipsum lacus, placerat vitae lorem non, condimentum sagittis nibh. Mauris sagittis vulputate mi. Vestibulum ante ipsum primis </div></div>
    <div id="header"><div class="container">
      This is fixed and needs to stick when it reaches the top.
    </div></div>
    <div id="main"><div class="container">
      <p>Aut commodo massa diam quis elit. Vestibulum euismod vitae justo nec tempus. Duis venenatis venenatis arcu, sit amet varius libero. Nullam porta arcu at massa iaculis, at feugiat erat blandit. Vestibulum in tincidunt justo. Vivamus eget mollis arcu, ac aliquet ipsum.</p>

<p>Pellentesque diam metus, pretium nec odio vel, fermentum feugiat lectus. Aenean lacus est, dignissim ut accumsan faucibus, vehicula vel diam. Donec arcu justo, sodales nec nibh in, lobortis sollicitudin neque. Vivamus suscipit velit pulvinar sem imperdiet, vitae porttitor diam euismod. Ut mauris est, consequat at feugiat vel, mattis nec quam. Ut dictum erat vitae ullamcorper fringilla. Cras et lorem at dui pulvinar condimentum vel id justo. Duis sagittis quam nec erat euismod, tempus elementum dui mollis. Morbi eu nisl ultricies, imperdiet tellus sodales, lacinia quam.</p>

<p>Pellentesque diam metus, pretium nec odio vel, fermentum feugiat lectus. Aenean lacus est, dignissim ut accumsan faucibus, vehicula vel diam. Donec arcu justo, sodales nec nibh in, lobortis sollicitudin neque. Vivamus suscipit velit pulvinar sem imperdiet, vitae porttitor diam euismod. Ut mauris est, consequat at feugiat vel, mattis nec quam. Ut dictum erat vitae ullamcorper fringilla. Cras et lorem at dui pulvinar condimentum vel id justo. Duis sagittis quam nec erat euismod, tempus elementum dui mollis. Morbi eu nisl ultricies, imperdiet tellus sodales, lacinia quam.</p>

<p>Pellentesque diam metus, pretium nec odio vel, fermentum feugiat lectus. Aenean lacus est, dignissim ut accumsan faucibus, vehicula vel diam. Donec arcu justo, sodales nec nibh in, lobortis sollicitudin neque. Vivamus suscipit velit pulvinar sem imperdiet, vitae porttitor diam euismod. Ut mauris est, consequat at feugiat vel, mattis nec quam. Ut dictum erat vitae ullamcorper fringilla. Cras et lorem at dui pulvinar condimentum vel id justo. Duis sagittis quam nec erat euismod, tempus elementum dui mollis. Morbi eu nisl ultricies, imperdiet tellus sodales, lacinia quam.</p>

<p>Pellentesque diam metus, pretium nec odio vel, fermentum feugiat lectus. Aenean lacus est, dignissim ut accumsan faucibus, vehicula vel diam. Donec arcu justo, sodales nec nibh in, lobortis sollicitudin neque. Vivamus suscipit velit pulvinar sem imperdiet, vitae porttitor diam euismod. Ut mauris est, consequat at feugiat vel, mattis nec quam. Ut dictum erat vitae ullamcorper fringilla. Cras et lorem at dui pulvinar condimentum vel id justo. Duis sagittis quam nec erat euismod, tempus elementum dui mollis. Morbi eu nisl ultricies, imperdiet tellus sodales, lacinia quam.</p>

<p>Pellentesque diam metus, pretium nec odio vel, fermentum feugiat lectus. Aenean lacus est, dignissim ut accumsan faucibus, vehicula vel diam. Donec arcu justo, sodales nec nibh in, lobortis sollicitudin neque. Vivamus suscipit velit pulvinar sem imperdiet, vitae porttitor diam euismod. Ut mauris est, consequat at feugiat vel, mattis nec quam. Ut dictum erat vitae ullamcorper fringilla. Cras et lorem at dui pulvinar condimentum vel id justo. Duis sagittis quam nec erat euismod, tempus elementum dui mollis. Morbi eu nisl ultricies, imperdiet tellus sodales, lacinia quam.</p>

<p>Pellentesque diam metus, pretium nec odio vel, fermentum feugiat lectus. Aenean lacus est, dignissim ut accumsan faucibus, vehicula vel diam. Donec arcu justo, sodales nec nibh in, lobortis sollicitudin neque. Vivamus suscipit velit pulvinar sem imperdiet, vitae porttitor diam euismod. Ut mauris est, consequat at feugiat vel, mattis nec quam. Ut dictum erat vitae ullamcorper fringilla. Cras et lorem at dui pulvinar condimentum vel id justo. Duis sagittis quam nec erat euismod, tempus elementum dui mollis. Morbi eu nisl ultricies, imperdiet tellus sodales, lacinia quam.</p>

<p>Sed tempor, eros ut gravida ultricies, eros ex scelerisque arcu, in sodales ex ex eu diam. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Curabitur lorem lectus, tincidunt lacinia felis quis, pulvinar sodales eros. Praesent diam nulla, commodo at semper at, lacinia quis velit. Quisque consequat tortor vel scelerisque viverra. Morbi vel finibus nisl. Aliquam eget dui non ligula pharetra sagittis. Curabitur vel porttitor ipsum. Cras imperdiet egestas posuere. Integer urna lacus, tristique a rutrum sed, malesuada in purus. Suspendisse potenti. In ullamcorper nisi mi.</p>
    </div></div>
  </body>
</html>
              
            
!

CSS

              
                body {
  font-family: Arial;
  padding: 0;
  margin: 0;
}
#announcement {
  background: #ff0000;
  color: navy;
  padding: 20px 0px;
}
#header {
  background-color: black;
  color: white;
  line-height: 58px;
  width: 100%;
  position: fixed;
  height: 58px;
}
#main {
  padding: 20px 0px;
  margin-top: 58px; /* Header Height */
}
.container {
  max-width: 700px;
  margin: 0px auto;
}
              
            
!

JS

              
                var requestId = null;

window.addEventListener("resize", function() {
  if (!requestId) {
    requestId = requestAnimationFrame(resize);
  }
});

function resize() {
  // this is just needed for codepen because you can resize viewport to zero and it would throw off calculations
  if (window.innerWidth < 10) {
    requestId = null;
    return;
  }   
  
  // Drag header up with announcement
  var announcement = document.getElementById('announcement');
  gsap.fromTo('#header', { top: () => announcement.offsetHeight }, {
      top: 0,
      ease: 'none',
      scrollTrigger: {
        trigger: '#announcement',  
        start: 'top top',
        end: 'bottom top',
        scrub: true,
        invalidateOnRefresh: true
      }
    });

  requestId = null;
}

 window.addEventListener('DOMContentLoaded', (event) => {
   resize();
 });

              
            
!
999px

Console