Pen Settings

HTML

CSS

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

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

Behavior

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.

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

              
                 <div class="header">
   <div class="top-section">
     Header top section!
   </div>
   <div class="menu-section-holder">
     <div class="menu-section">
       <ul class="navbar">
          <li>Home</li>
          <li>About</li>
          <li>Products</li>
          <li>Contact</li>
       </ul>
     </div>
   </div>
</div>
<div class="page">
  <img src="https://www.targetdevelop.com/wp-content/uploads/2018/09/target-develop-contact-us.jpg" alt="">
</div>
              
            
!

CSS

              
                *{
  box-sizing: border-box;
  -moz-box-sizing: border-box;
  -webkit-box-sizing: border-box;
  font-family: arial;
  padding: 0;
  margin: 0;
}
.header{
  width: 100%;
}
.top-section{
  padding: 10px 20px;
  border-bottom: 1px solid #999;
}
.menu-section{
  background-color: #fff;
  width: 100%;
  &.stick{
    position: fixed;
    top: 0;
  }
}
.navbar{
  list-style: none;
  padding: 0;
  margin: 0;
  border-bottom: 1px solid #999;
  
  > li{
    display: inline-block;
    padding: 10px 20px;
  }
}
.page{
  padding: 0;
  height: 2000px;
  background-color: #ccc;
  widtg: 100%;
  overflow: hidden;
}
              
            
!

JS

              
                var header = $('.header');
var menuSection = $('.menu-section');
var menuSectionHolder = $('.menu-section-holder');

// assign the main header height
// to header holder
menuSectionHolder.css('height', menuSection.outerHeight());

// find the top of menu section
// from its holder
var menuOffsetTop = menuSectionHolder.offset().top;

// checks callback on every scroll pixel
$(window).on('scroll', function(){
  
  // find top position of scroll
  var _scrollTop = $(window).scrollTop();
  
  // checks if scroll top is equal to
  // menu section top position
  if(_scrollTop >= menuOffsetTop){
    menuSection.addClass('stick'); // adds 'stick' class to menu section
  }
  else{
    menuSection.removeClass('stick'); // remove 'stick' class when it's back
  }
});
              
            
!
999px

Console