How to make a drop-down menu inline with rest of navigation bar and make it responsive in a navicon(hamburger)menu?

I am having trouble with my navigation menu. My navigation menu is responsive so the navigation uses a navicon (hamburger menu) in mobile version. I changed one of my menu tabs (portfolio) to a dropdown menu. When I did this, the portfolio tab is now not inline with the rest of the navigation menu. In mobile version it also stays outside the navicon menu. I have no idea how I am supposed to fix this?

function myDropdownMenu() {
  document.getElementById("myDropdown").classList.toggle("show");
}

window.onclick = function(e) {
  if (!e.target.matches('.dropButton')) {
    var myDropdown = document.getElementById("myDropdown");
    if (myDropdown.classList.contains('show')) {
      myDropdown.classList.remove('show');
    }
  }
}

function myFunction() {
  var x = document.getElementById("myNavbar");
  if (x.className === "navbar") {
    x.className += " responsive";
  } else {
    x.className = "navbar";
  }
}
.navbar {
  overflow: hidden;
  background-color: white;
}

.navbar a {
  float: left;
  display: block;
  color: black;
  text-align: center;
  padding: 14px 17px;
  text-decoration: none;
  font-size: 20px;
  font-family: Brush Script MT, Brush Script Std, cursive;
}

.navbar a:hover,
.dropdown:hover .dropButton,
.dropButton:focus {
  color: #DCAE1D;
}

.dropdown {
  float: left;
  overflow: hidden;
}

.dropdown .dropButton {
  cursor: pointer;
  font-size: 20px;
  border: none;
  background-color: inherit;
  font-family: Brush Script MT, Brush Script Std, cursive;
  margin: 0;
}

.dropdown-content {
  display: none;
  position: absolute;
  min-width: 160px;
}

.dropdown-content a {
  float: none;
  padding: 12px 16px;
  text-decoration: none;
  display: block;
  text-align: left;
}

.show {
  display: block;
}

.navbar img {
  width: auto;
  height: 200px;
  margin-top: -80px;
}

.navbar .icon {
  display: none;
}

@media screen and (max-width: 600px) {
  .navbar a:not(:first-child) {
    display: none;
  }
  .navbar a.icon {
    float: right;
    display: block;
  }
}

@media screen and (max-width: 600px) {
  .navbar.responsive {
    position: relative;
  }
  .navbar.responsive .icon {
    position: absolute;
    right: 0;
    top: 0;
  }
  .navbar.responsive a {
    float: none;
    display: block;
    text-align: left;
  }
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">

<div class="navbar" id="myNavbar">
  <a href="index.htm"><img src="arg_logo.jpg" alt="Logo for Amber Rose Photography" /></a>
  <a href="index.htm">Home</a>
  <a href="arg_bio.htm">About</a>

  <div class="dropdown">
    <div class="dropButton" onclick="myDropdownMenu()">Portfolio
      <i class="fa fa-caret-down"></i>
    </div>
    <div class="dropdown-content" id="myDropdown">
      <a href="arg_gallery.htm#nature">Nature</a>
      <a href="arg_gallery.htm#travel">Travel</a>
      <a href="arg_gallery.htm#portraits">Portraits</a>
    </div>
  </div>
  <a href="arg_table.htm">Prices</a>
  <a href="arg_form.htm">Quote</a>
  <a href="arg_contact.htm">Contact</a>
  <a href="arg_links.htm">Links</a>
  <a href="arg_sitemap.htm">Site Map</a>
  <a href="javascript:void(0);" class="icon" onclick="myFunction()">
    <i class="fa fa-bars"></i>
  </a>
</div>

Source: Ask Javascript Questions

LEAVE A COMMENT