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

              
                <body>

  <nav>
    <input type="checkbox" id="toggle" />
    <label for="toggle" class="hamburger">&#9776;</label>
    <!--     add a javascript function to hide the menu after being clicked -->
    <ul onclick="hidemenu()">
      <li><a href="#">Home</a></li>
      <li><a href="#">Information</a>
        <ul>
          <li><a href="#">Services</a></li>
          <li><a href="#">Support</a></li>
          <li><a href="#">Products</a></li>
        </ul>
      </li>
      <li><a href="#">About</a></li>
      <li><a href="#">News</a></li>
      <li><a href="#">Contact</a></li>
    </ul>
  </nav>

</body>
              
            
!

CSS

              
                * {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: verdana, sans-serif;
  margin: 2em;
  padding: 0;
}

nav {
  width: 100%;
  position: fixed;
  top: 0;
  left: 0;
  background-color: silver;
}

nav ul {
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: flex-end;
}

nav ul li {
  flex: 0 0 8rem; /*the same as flex-grow, flex-shrink, flex-basis */
  text-align: center;
}

/* we turn off the underline and set the padding and the color O */

nav ul li a {
  text-decoration: none;
  padding: 0.8rem 1rem;
  display: block;
  color: green;
}

/* feedback for the user with a background when hovering hover */

nav ul li:hover {
  background-color: black;
}

nav ul li a:hover {
  color: white;
}

/* sub menus */

li ul {
  display: none;
  position: absolute;
  background-color: black;
}

li ul li a {
  padding: 0.3rem 1.5rem;
  /*   font-size: 0.8rem; */
}

nav ul li:hover ul {
  display: flex;
  flex-direction: column;
}

nav ul li ul li {
  flex: 0 1 auto;
  width: 8rem; /* the same as the value for flex-basis on the parent li */
}

/* now for the smaller displays */

@media screen and (max-width: 900px) {
  nav ul {
    flex-direction: column;
  }

  li ul {
    position: static;
  }

  nav ul li {
    flex: 0 0 auto; /*the same as flex-grow, flex-shrink, flex-basis */
    width: 100%;
  }

  nav ul li:hover ul {
    display: flex;
    flex-direction: column;
    width: 100%;
  }
}

/* Now let’s try with the hamburger menu

In this version we need to use a hamburger menu item that will reveal the menu. For this we need a checkbox as input that will toggle this on and off.

We need to add this the following HTML inside the nav */

/* <input type="checkbox" id="toggle">
<label for="toggle" class="hamburger">&#9776;</label> */

/* Note that ☰ is an HTML entity that displays the ☰ (hamburger icon.)

Now in the CSS we need to hide this item when we are in the normal wide screen view: */

/* we hide the hamburger icon until we are on a small screen */

input[type="checkbox"] {
  display: none;
}

.hamburger {
  display: none;
  font-size: 2rem;
  color: white;
  margin-right: 0.8em;
}

/* So when the display is small we can use our media query to hide the menu but reveal the hamburger */

@media screen and (max-width: 900px) {
  .hamburger {
    display: block;
    float: right;
    cursor: pointer;
  }

  /*   but we also need to hide the menu until that hamburger is clicked */

  nav ul {
    display: none;
  }

  /*when the hamburger is clicked the ul below it will be made to show */
  /*  the tilda ~ points to the next sibling selector */

  input[type="checkbox"]:checked ~ ul {
    display: block;
  }
}

              
            
!

JS

              
                function hidemenu() {
  document.getElementById("toggle").checked = false;
}

              
            
!
999px

Console