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

              
                <div class="wrapper">
  <h2>How to make sticky menu stick to wrapper/container.</h2>
</div>
<div class="menu"></div>
              
            
!

CSS

              
                body{
  background: #e3e3e3;
  padding-bottom: 1000px;
}
.wrapper {
  width: 600px;
  min-height: 400px;
  display: block;
  background: #fff;
  margin:100px auto;
  text-align:center;
}
h2 {
  padding:20px 0;
  
}
.menu{
  background: #ccc;
  width:100px;
  height: 200px;
  display: block;
  position: fixed;
  top: 0;
  left: 0;
}
              
            
!

JS

              
                //Start after window load so not messy jumping effect.
// else menu appear top 0 left 0 than jump calculated position
// TODO : If page loads when scrolled way down , menu placed wrong position.So check position for it.

$(window).load(function(){
    
  var container        = $('.wrapper'), // Container Div
      containerPos     = container.offset(), // Container Offset
      containerWidth   = container.width(),//Container Width
      margin           = 10, // Menu Margin to Container
      menu             = $('.menu');
      // Lets Set Menu left location
      menu.css({
        // Menu top position must be container offset top.
        top:containerPos.top,
        // Menu left position Container Width + Container Offset Left + Margin
        left:containerWidth+containerPos.left+margin
      });
      $(window).scroll(function() {
        // Lets calculate bottom corner offset top when menu hit container bottom
        var bottomOffset = container.height()- menu.height();
        // 
        if($(window).scrollTop()>=bottomOffset){
          // When it hits corner we have to determine margin value top of menu.
          var margintop= $(window).scrollTop() - (container.height() - menu.height());
          menu.css({
            marginTop:-margintop
          });
        }else {
          //Dont ask
          menu.css({
            marginTop:0
          });
        }
      });
    
});
              
            
!
999px

Console