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

              
                <nav class="navbar">
  <div class="container">

    <div class="navbar-header">
      <button class="navbar-toggler" data-toggle="open-navbar1">
        <span></span>
        <span></span>
        <span></span>
      </button>
      <a href="#">
        <h4>Awesome<span>logo</span></h4>
      </a>
    </div>

    <div class="navbar-menu" id="open-navbar1">
      <ul class="navbar-nav">
        <li class="active"><a href="#">Home</a></li>
        <li class="navbar-dropdown">
          <a href="#" class="dropdown-toggler" data-dropdown="my-dropdown-id">
            Categories <i class="fa fa-angle-down"></i>
          </a>
          <ul class="dropdown" id="my-dropdown-id">
            <li><a href="#">Actions</a></li>
            <li><a href="#">Something else here</a></li>
            <li class="separator"></li>
            <li><a href="#">Seprated link</a></li>
            <li class="separator"></li>
            <li><a href="#">One more seprated link.</a></li>
          </ul>
        </li>
        <li class="navbar-dropdown">
          <a href="#" class="dropdown-toggler" data-dropdown="blog">
            Blog <i class="fa fa-angle-down"></i>
          </a>
          <ul class="dropdown" id="blog">
            <li><a href="#">Some category</a></li>
            <li><a href="#">Some another category</a></li>
            <li class="separator"></li>
            <li><a href="#">Seprated link</a></li>
            <li class="separator"></li>
            <li><a href="#">One more seprated link.</a></li>
          </ul>
        </li>
        <li><a href="#">About</a></li>
        <li><a href="#">Contact</a></li>
        <li><a href="#">Signin</a></li>
      </ul>
    </div>
  </div>
</nav>
              
            
!

CSS

              
                @import url('https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500&display=swap');

$font-family: 'Roboto', sans-serif;
$font-size-base: 0.925rem;
$base-color: #66f;
$text-dark: #3c4250;
$border-color: #eceef3;

$navbar-body-color: #fff;
// $navbar-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.035);
$navbar-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
$navbar-padding-y: 1rem;
$navbar-padding-x: 1.15rem;

$navbar-link-hover: $base-color;
$navbar-link-padding-y: 0.5rem;
$navbar-link-padding-x: 1rem;

$navbar-dropdown-padding-y: 0.5rem;
$navbar-dropdown-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.1);
$navbar-dropdown-radius: 0.75rem;

$navbar-dropdown-item-padding-y: 0.25rem;
$navbar-dropdown-item-padding-x: 1rem;

$navbar-dropdown-separator-margin-y: 9px;
$navbar-dropdown-separator-color: $border-color;

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

body {
  font-family: $font-family;
  font-size: $font-size-base;
}

a {
  text-decoration: none;
}

.container {
  width: 1170px;
  position: relative;
  margin: {
    left: auto;
    right: auto;
  }
  padding: {
    left: 15px;
    right: 15px;
  }
}

// Start navbar

.navbar,
.navbar > .container {
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  @media (max-width: 768px) {
    display: block;
  }
}

.navbar {
  box-shadow: $navbar-shadow;
  background-color: $navbar-body-color;
  padding: $navbar-padding-y $navbar-padding-x;
  border-bottom: 1px solid $border-color;

  .container {
    @media (min-width: 576px) {
      max-width: 540px;
    }
    @media (min-width: 768px) {
      max-width: 720px;
    }
    @media (min-width: 992px) {
      max-width: 960px;
    }
    @media (min-width: 1200px) {
      max-width: 1140px;
    }
  }

  /*
  |-----------------------------------
  | Start navbar logo or brand etc..
  |-----------------------------------
  */
  .navbar-header {
    display: flex;
    align-items: center;

    @media (max-width: 768px) {
      width: 100%;
      display: flex;
      align-items: center;
      justify-content: space-between;
      flex-direction: row-reverse;
    }

    .navbar-toggler {
      // border-radius: 5px;
      // background-color: transparent;
      cursor: pointer;
      border: none;
      display: none;
      outline: none;

      @media (max-width: 768px) { display: block }

      span {
        height: 2px;
        width: 22px;
        background-color: lighten($text-dark, 35%);
        display: block;
      }
      span:not(:last-child) {
        margin-bottom: 0.2rem;
      }
    }

    > a {
      font-weight: 500;
      color: $text-dark;
    }
  }

  /*
  |-----------------------------------
  | Start navbar menu
  |-----------------------------------
  */
  .navbar-menu {
    display: flex;
    align-items: center;
    flex-basis: auto;
    flex-grow: 1;

    @media (max-width: 768px) {
      display: none;
      text-align: center;
    }
 
    &.active {
      display: flex !important;
    }

    // Ul
    .navbar-nav {
      margin-left: auto;
      flex-direction: row;
      display: flex;
      padding-left: 0;
      margin-bottom: 0;
      list-style: none;

      @media (max-width: 768px) {
        width: 100%;
        display: block;
        border-top: 1px solid #EEE;
        margin-top: 1rem;
      }

      > li {
        > a {
          color: $text-dark;
          text-decoration: none;
          display: inline-block;
          padding: $navbar-link-padding-y $navbar-link-padding-x;
          &:hover {
            color: $navbar-link-hover;
          }
          @media (max-width: 768px) {
            border-bottom: 1px solid $border-color;
          }
        }
        &.active {
          a {
            color: $base-color;
          }
        }
      }

      .navbar-dropdown {
        .dropdown {
          list-style: none;
          position: absolute;
          top: 150%;
          left: 0;
          background-color: #fff;
          padding-top: $navbar-dropdown-padding-y;
          padding-bottom: $navbar-dropdown-padding-y;
          min-width: 160px;
          width: auto;
          white-space: nowrap;
          box-shadow: $navbar-dropdown-shadow;
          z-index: 99999;
          border-radius: $navbar-dropdown-radius;
          display: none;
          @media (max-width: 768px) {
            position: relative;
            box-shadow: none;
          }
          li {
            a {
              color: $text-dark;
              padding: $navbar-dropdown-item-padding-y
                       $navbar-dropdown-item-padding-x;
              display: block;
            }
          }
          &.show {
            display: block !important;
          }
        }
      }

      .dropdown > .separator {
        height: 1px;
        width: 100%;
        margin: {
          top: $navbar-dropdown-separator-margin-y;
          bottom: $navbar-dropdown-separator-margin-y;
        };
        background-color: $navbar-dropdown-separator-color;
      }
    }
  }

  .navbar-dropdown {
    position: relative;
  }
}


// Custom
.navbar .navbar-header > a span {
  color: $base-color;
}
.navbar .navbar-header h4 {
  font-weight: 500;
  font-size: 1.25rem;
  @media (max-width: 768px) {
    font-size: 1.05rem;
  }
}

              
            
!

JS

              
                // Other important pens.
// Map: https://codepen.io/themustafaomar/pen/ZEGJeZq
// Dashboard: https://codepen.io/themustafaomar/pen/jLMPKm

let dropdowns = document.querySelectorAll('.navbar .dropdown-toggler')
let dropdownIsOpen = false

// Handle dropdown menues
if (dropdowns.length) {
  // Usually I don't recommend doing this (adding many event listeners to elements have the same handler)
  // Instead use event delegation: https://javascript.info/event-delegation
  // Why: https://gomakethings.com/why-event-delegation-is-a-better-way-to-listen-for-events-in-vanilla-js
  // But since we only have two dropdowns, no problem with that. 
  dropdowns.forEach((dropdown) => {
    dropdown.addEventListener('click', (event) => {
      let target = document.querySelector(`#${event.target.dataset.dropdown}`)

      if (target) {
        if (target.classList.contains('show')) {
          target.classList.remove('show')
          dropdownIsOpen = false
        } else {
          target.classList.add('show')
          dropdownIsOpen = true
        }
      }
    })
  })
}

// Handle closing dropdowns if a user clicked the body
window.addEventListener('mouseup', (event) => {
  if (dropdownIsOpen) {
    dropdowns.forEach((dropdownButton) => {
      let dropdown = document.querySelector(`#${dropdownButton.dataset.dropdown}`)
      let targetIsDropdown = dropdown == event.target

      if (dropdownButton == event.target) {
        return
      }

      if ((!targetIsDropdown) && (!dropdown.contains(event.target))) {
        dropdown.classList.remove('show')
      }
    })
  }
})

// Open links in mobiles
function handleSmallScreens() {
  document.querySelector('.navbar-toggler')
    .addEventListener('click', () => {
      let navbarMenu = document.querySelector('.navbar-menu')

      if (!navbarMenu.classList.contains('active')) {
        navbarMenu.classList.add('active')
      } else {
        navbarMenu.classList.remove('active')
      }
    })
}

handleSmallScreens()

              
            
!
999px

Console