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

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

              
                <h1 style="text-align:center; font-weight: bold; padding: 10px 0;">Responsive menu: resize viewport to less than 768px</h1>
<div class="container container-nav">

  <nav class="top-nav">
    <span class="dropdown-toggle">
      <i class="fa fa-bars"></i> Menu&nbsp;&nbsp;<i class="menu-chevron fa fa-chevron-down"></i>
    </span>
    <ul class="navigation">
      <li class="nav-item"><a href="#" > Item1 </a></li>
      <li class="nav-item"><a href="#"> Item2 </a></li>
      <li class="nav-item"><a href="#" > Item3 </a></li>
      <li class="nav-item"><a href="#"> Item4 </a></li>
      <li class="nav-item"><a href="#"> Item5 </a></li>
      <li class="nav-item"><a href="#"> Item6 </a></li>
      <li class="nav-item"><a href="#"> Item7 </a></li>
      <li class="nav-item"><a href="#"> Item8 </a></li>
      <li class="nav-item"><a href="#"> Item9 </a></li>
      <li class="nav-item"><a href="#"> Item10</a></li>
    </ul>

  </nav>

</div>
<div style="">
  <hr style="width: 250px; "> Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It
  has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop
  publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</div>
              
            
!

CSS

              
                *,
*:before,
*:after {
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
}

body {
  font-family: Arial;
}

a,
a:hover,
a:visited {
  text-decoration: none;
}

img {
  height: auto;
  max-width: 100%;
}
nav {
  position: relative;
}
.container-nav {
    text-align: center;
    border: 1px solid red;
}

.dropdown-toggle {
  font-weight: bold;
  font-size: 18px;
  color: #fff;
  padding: 0 10px;
  border-radius: 5px 5px 0 0;
  position: absolute;
  left: 20px;
  height: 40px;
  line-height: 40px;
  opacity: 0.9;
  background: #616262;
  z-index: 10000;
}

.navigation {
  /* display: none; */
  font-weight: bold;
  font-size: 18px;
  color: #ffffff;
  list-style: none;
  position: absolute;
  top: 40px;
  left: 20px;
  z-index: 0;
  padding: 5px 10px;
  border-radius: 0 5px 5px 5px;
  opacity: 0.9;
  background-color: #616262;
}
.navigation li {
  //display: list-item;
  float: left;
  clear: left;
  height: 40px;
  line-height: 40px;
  width: 140px;
  border: 1px solid #808080;
  border-radius: 5px;
}

.navigation a:hover,
.navigation a:focus,
.navigation a:active {
  text-decoration: none;
}
.navigation:active,
li:active {
  //background: red;
}

.navigation li a {
  color: #fff;
}

.hiding {
    display: none;
}

@media (min-width: 768px) {
    .container-nav {
        text-align: center;
        border: 1px solid blue;
        
    }
    .dropdown-toggle {
        display: none;
    }
    .navigation {
        display: block;
        width: 100%;
        position: static;
        background-color: #ffffff;
/*        top: auto;
        left: auto;*/
    }  
    .navigation li {

        display: inline-block;
        height: 42px;
        line-height: 42px;
        float: none;
        background-color: #3f030f;
        color: white;
        text-decoration: none;
        border: none;
        border-radius: 5px;
/*        border: 1px solid whitesmoke;*/
        padding: 0 10px;
        width: auto;
    }
}
              
            
!

JS

              
                var elem1 = $(".dropdown-toggle");
var elem2 = $("li:last-child");
var elem3 = $(".navigation");

elem1.click(function() {

  // elem3.delay(100).slideToggle();
  elem3.toggleClass('hiding');
  $(".menu-chevron").toggleClass('fa-chevron-down').toggleClass('fa-chevron-up');
  
});

// if mobile menu is shown and screen is resized to desktop size and back 
// mobile menu must be in hidden state
$(window).resize(function() {
  
  var winwidth = $(window).innerWidth();
  
  if(winwidth < 768) {
    //console.log(winwidth);
    /* $('.navigation').removeClass('showing').removeClass('hiding'); */
    if (!elem3.hasClass('hiding')) {
         elem3.addClass('hiding');
      // if mobile navigation is hidden, the chevron must point down   
      if ($(".menu-chevron").hasClass('fa-chevron-up')) {
        $(".menu-chevron").toggleClass('fa-chevron-up').toggleClass('fa-chevron-down');
     }   
  }
  }
});
              
            
!
999px

Console