What do you think of my navigation bar?

I’ve created a navbar for a website that I’ve just started working on. I would like feedback on what everyone thinks and if you may have any additional suggestions on improvements for the navbar.

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>Lawton Drum Co.</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">
            Parts <i class="fa fa-angle-down"></i>
          </a>
          <ul class="dropdown" id="my-dropdown-id">
            <li><a href="#">Snare</a></li>
            <li class="separator"></li>
            <li><a href="#">Bass</a></li>
            <li class="separator"></li>
            <li><a href="#">Tom</a></li>
            <li class="separator"></li>
            <li><a href="#">Accesories</a></li>
          </ul>
        </li>
        <li class="navbar-dropdown">
          <a href="#" class="dropdown-toggler" data-dropdown="blog">
            Services <i class="fa fa-angle-down"></i>
          </a>
          <ul class="dropdown" id="blog">
            <li><a href="#">Restoration</a></li>
            <li class="separator"></li>
            <li><a href="#">Refinishing</a></li>
            <li class="separator"></li>
            <li><a href="#">Custom Building</a></li>
          </ul>
        </li>
        <li><a href="#">About</a></li>
        <li><a href="#">Contact</a></li>
        <li><a href="#">PA Drum Show</a></li>
        <li><a href="#">Links</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: #ececec;

$navbar-body-color: #fff;
$navbar-link-hover: $base-color;
$navbar-dropdown-separator-color: #eee;
$navbar-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.035);

* {
  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 {
  padding: 1.15rem 1rem;
  box-shadow: $navbar-shadow;
  background-color: $navbar-body-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;
    flex-basis: auto;
    flex-grow: 1;
    align-items: center;

    @media (max-width: 768px) {
      display: none;
      text-align: center;
    }

    // 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: 0.5rem 1rem;
          &:hover {
            color: $navbar-link-hover;
          }
          @media (max-width: 768px) {
            border-bottom: 1px solid #EEE;
          }
        }
        &.active {
          a {
            color: $base-color;
          }
        }
      }

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

      .dropdown > .separator {
        height: 1px;
        width: 100%;
        margin: 9px 0;
        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;
  }
}


Javascript:

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

// Handle dropdown menues
if (dropdowns.length) {
  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.style.display === 'flex') {
      navbarMenu.style.display = 'none'
      return
    }

    navbarMenu.style.display = 'flex'
  })
}

handleSmallScreens()e code here

I would also like to put the Facebook logo and have it linked to the owners FB page in the navbar to the far right. Not sure how to do that though? Any help would be greatly appreciated!

1 Like

Hi @AJ20211!

You might get more responses if people could see the final result. Could you throw you code into codepen or js fiddle and share the link with the forum?

2 Likes

https://codepen.io/AJ2021/pen/MWeMaJL

Something seems to be wrong with my css code. If anyone could help me fix it, it would be greatly appreciated!

I think it looks good.

The main thing that I noticed was that the button to toggle the menu was really small. So maybe you could make that a little bit bigger and add a cursor pointer to it in css.

Also, you are referencing a font awesome icon but I don’t see that displayed in the final result. So it looks like the font awesome link is missing.

For your CSS you do have these issues which are invalid syntax

// Start navbar
// Custom

It looks like syntax issues are preventing your styles from working. I would run my code through the css validator to get a more detailed report of the issues.

1 Like

I don’t see where I am referencing a font awesome icon. Also when I try to validate the css code, it comes back with the following errors:

URI : TextArea
3 Parse Error $font-family: ‘Roboto’, sans-serif;
4 Parse Error $font-size-base: 0.925rem;
5 Parse Error $base-color: #66f;
6 Parse Error $text-dark: #3c4250;
7 Parse Error $border-color: #ececec;
9 Parse Error $navbar-body-color: #fff;
10 Parse Error $navbar-link-hover: $base-color;
11 Parse Error $navbar-dropdown-separator-color: #eee;
12 Parse Error $navbar-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.035);
21 body Value Error : font-family Parse Error $font-family
22 body Value Error : font-size Parse Error $font-size-base
39 .container Value Error : margin Parse Error : { left: auto; right: auto; } padding: { left: 15px; right: 15px; }
50 .navbar, .navbar .container Parse Error @media (max-width: 768px) { display: block; }
51 .navbar, .navbar .container Parse Error }
55 .navbar Parse Error $navbar-shadow
56 .navbar Value Error : background-color Parse Error $navbar-body-color
212 .navbar Parse Error .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; flex-basis: auto; flex-grow: 1; align-items: center; @media (max-width: 768px) { display: none; text-align: center; } // 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: 0.5rem 1rem; &:hover { color: $navbar-link-hover; } @media (max-width: 768px) { border-bottom: 1px solid #EEE; } } &.active { a { color: $base-color; } } } .navbar-dropdown { .dropdown { list-style: none; position: absolute; top: 150%; left: 0; background-color: #fff; padding: 0.5rem 0; min-width: 160px; width: auto; white-space: nowrap; box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.1); z-index: 99999; border-radius: 0.75rem; display: none; @media (max-width: 768px) { position: relative; box-shadow: none; } li { a { color: $text-dark; padding: 0.25rem 1rem; display: block; } } &.show { display: block !important; } } } .dropdown > .separator { height: 1px; width: 100%; margin: 9px 0; background-color: $navbar-dropdown-separator-color; } } } .navbar-dropdown { position: relative; }
215 .navbar .navbar-header > a span Value Error : color Parse Error $base-color
222 .navbar .navbar-header h4 Parse Error @media (max-width: 768px) { font-size: 1.05rem; }
223 .navbar .navbar-header h4 Parse Error }

I don’t seem to understand the errors, any help understanding these would be greatly appreciated!

1 Like

Oh and also the navbar is suppose to be horizontal across the top of the page.

1 Like

This is was the font awesome icon I was referring to.

You could probably ignore the first like 6 errors since it is dealing with sass and it doesn’t look like the validator is registering that.

The majority of your issues are with your use of media queries.

  @media (max-width: 768px) {
      display: none;
      text-align: center;
    }

When I started to mess with the css file and reformat the media queries to look like this.

@media (max-width: 768px) {
      .navbar-menu {
         display: none;
         text-align: center;
      }
    }

I started to see the css styles take place.

Hope that helps!

1 Like

It seems that you’re using SCSS, not CSS. In codepen;

  1. click the Settings button
  2. choose CSS from the left side menu
  3. in ‘CSS Processor’ select SCSS

Edit: the navbar is horizontal when you select the correct preprocessor. Are you having issues? Or just wanting feedback?

2 Likes

Thanks for that. It looks as if I am using SCSS instead of CSS. Not sure the difference, but thanks Roma for pointing that out!

1 Like

Thanks for all your help so far!

2 Likes

I was looking at it with just plain css and that was why there were so many issues with your page. Now it works. Thanks @Roma!

In plain css that’s how to format media queries.

1 Like

How do I add the Facebook icon to the navbar on the far right?

1 Like

Do you want the facebook icon right next to the links?

1 Like

Yes, I would like it to be on the right side, next to the links.

1 Like

Have you tried just adding another list item with the facebook icon below the links list item in your html?

1 Like

No I haven’t… Guess I could just do that and it would work.

1 Like

facebook icon

1 Like

Was wondering too, how would I add a navbar at the bottom of the page, where I could put a link to our email address and so forth like some pages have?

1 Like

I guess you could create a nice footer for all of that information.

1 Like