cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-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.

            
              <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>
            
          
!
            
              * {
  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;
}
            
          
!
            
              $(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
Loading ..................

Console