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 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

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

              
                <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>

<div class="wrapper">
  <header>
    <p>coding is love</p>
  </header>
  <div class="nav-bar">
    <nav>
      <ul>
        <li><a href="#">home</a></li>
        <li><a href="#">tutorials</a></li>
        <li><a href="#">ui school</a></li>
        <li><a href="#">quick tips</a></li>
        <li><a href="#">forum</a></li>
      </ul>
    </nav>
  </div>


  <div class="main-content">
    <div class="content">
      Lorem ipsum dolor sit amet, consectetur adipisicing elit. Facilis exercitationem veritatis odio vitae incidunt commodi illum. Nulla mollitia, quisquam, debitis illum fugiat sapiente ut totam et vero officia sequi voluptatum. Lorem ipsum dolor sit amet,
      consectetur adipisicing elit. Accusantium ratione commodi debitis, earum blanditiis excepturi expedita quia deserunt error voluptatum, aliquam suscipit sit, mollitia asperiores. Voluptas debitis porro, adipisci saepe. Lorem ipsum dolor sit amet,
      consectetur adipisicing elit. Laudantium a, cum nihil omnis. Autem optio deserunt, tempora expedita, sint illum magnam ratione eaque incidunt ea error amet, doloribus dicta et! Lorem ipsum dolor sit amet, consectetur adipisicing elit. Laudantium
      a, cum nihil omnis. Autem optio deserunt, tempora expedita, sint illum magnam ratione eaque incidunt ea error amet, doloribus dicta et! Lorem ipsum dolor sit amet, consectetur adipisicing elit. Laudantium a, cum nihil omnis. Autem optio deserunt,
      tempora expedita, sint illum magnam ratione eaque incidunt ea error amet, doloribus dicta et! Lorem ipsum dolor sit amet, consectetur adipisicing elit. Laudantium a, cum nihil omnis. Autem optio deserunt, tempora expedita, sint illum magnam ratione
      eaque incidunt ea error amet, doloribus dicta et! Lorem ipsum dolor sit amet, consectetur adipisicing elit. Laudantium a, cum nihil omnis. Autem optio deserunt, tempora expedita, sint illum magnam ratione eaque incidunt ea error amet, doloribus
      dicta et! Lorem ipsum dolor sit amet, consectetur adipisicing elit. Laudantium a, cum nihil omnis. Autem optio deserunt, tempora expedita, sint illum magnam ratione eaque incidunt ea error amet, doloribus dicta et! Lorem ipsum dolor sit amet, consectetur
      adipisicing elit. Laudantium a, cum nihil omnis. Autem optio deserunt, tempora expedita, sint illum magnam ratione eaque incidunt ea error amet, doloribus dicta et! Lorem ipsum dolor sit amet, consectetur adipisicing elit. Laudantium a, cum nihil
      omnis. Autem optio deserunt, tempora expedita, sint illum magnam ratione eaque incidunt ea error amet, doloribus dicta et! Lorem ipsum dolor sit amet, consectetur adipisicing elit. Laudantium a, cum nihil omnis. Autem optio deserunt, tempora expedita,
      sint illum magnam ratione eaque incidunt ea error amet, doloribus dicta et!
    </div>


  </div>

</div>
              
            
!

CSS

              
                * {
  margin: 0;
  padding: 0;
}

body {
  background: #ccc;
}

.wrapper {
  width: 100%;
  overflow: hidden;
}

header {
  width: 100%;
  height: 250px;
  background: #00bfb6;
}

header p {
  text-align: center;
  font-weight: 900;
  font-family: cursive;
  font-size: 45px;
  color: #fff;
  line-height: 250px;
  margin-left: -80px;
}

nav {
  width: 100%;
  height: 75px;
  background: #fff;
  box-shadow: 0 2px 3px rgba(0, 0, 0, .4);
}

ul {
  list-style: none;
  width: 800px;
  margin: 0 auto;
}

ul li {
  float: left;
  width: 160px;
  line-height: 75px;
}

ul li:first-child {
  width: 100px;
  margin-left: 60px;
}

ul li a {
  text-decoration: none;
  text-transform: uppercase;
  color: #000;
  font-weight: 900;
  font-family: arial;
  font-size: 20px;
}

ul li a:hover {
  color: #00bfb6;
}

.main-content {
  width: 500px;
  margin: 0 auto;
  margin-top: 60px;
}

.content {
  margin-bottom: 30px;
  ;
}

.fixed {
  position: fixed;
  top: 0;
  height: 50px;
}

.fixed li {
  line-height: 50px;
}

.fixed li a {
  font-size: 16px;
}

.nav-bar {
  height: 50px;
}
              
            
!

JS

              
                $(function() {
  var offsetheight = $("nav").offset().top;

  $(this).scroll(function() {
    var scrolltopheight = $(this).scrollTop();

    if (scrolltopheight >= offsetheight) {
      $("nav").addClass("fixed");
    } else {
      $("nav").removeClass("fixed");
    }
  });
});

/*

 Now using the if else condition statement, we can achieve the ZoomIn - ZoomOut Sticky Navigation effect. if the scrolltopvalue is greater than or equal to the value of offsettopvalue. then it adds the fixed class to the nav element. class:fixed has the position:fixed;, top:0; and height: 50px; 
 so that the navigation bar height decreases from 75px to 50px and gets sticky at the top of the browser.
 
 For the proper ZoomIn - ZoomOut effect, we should set the  <code>line-height:50px;</code> and <code>font-size:16px;</code>.
 <pre>
 .fixed {
  position: fixed;
  top: 0;
  height: 50px;
}

.fixed li {
  line-height: 50px;
}

.fixed li a {
  font-size: 16px;
}
 
 </pre>

*/
              
            
!
999px

Console