0

I have a navigation menu on my website. It works, however when hovering over a menu item with sub-items they disappear when trying to click on them. It appears that there is a spacing issue with these items.

*Additionally, I am trying to figure out how to insert a | between the menu items. If you could share some insight that would be amazing. I only have basic coding knowledge as you can probably tell from my post.

I appreciate the assistance!

/* do not change */

.container {
  overflow: unset;
}

#container ul {
  margin: 0px;
  padding: 0px;
  list-style-type: none;
  display: inline-block;
}

#container ul li ul li {
  display: none;
}


/* can change */

#container {
  text-align: center;
}

#container ul li {
  width: 130px;
  height: 30px;
  line-height: 30px;
  float: left;
  text-align: center;
  margin: 5px;
  border-radius: 0px;
}

#container ul li a {
  color: black;
  text-decoration: none;
  font-weight: bold;
  display: block;
}

#container ul li a:hover {
  text-decoration: none;
  border-radius: 0px;
  color: #1dcdfe;
}

#container ul li:hover ul li {
  background-color: white;
  display: block;
  margin-left: 0px;
}
<div id="container">
  <ul>
    <li><a href='#scroll-home'>Home</a></li>
    <li><a href='#'>About Us</a>
      <ul>
        <li><a href='#scroll-whyhere'>Why You're Here</a></li>
        <li><a href='#scroll-ourmethod'>Our Method</a></li>
        <li><a href='#scroll-whyus'>Why Choose US</a></li>
        <li><a href='#scroll-testimonials'>Testimonials</a></li>
      </ul>
    </li>
    <li><a href='#'>Our Services</a>
      <ul>
        <li><a href='#scroll-wetreat'>What We Treat</a></li>
        <li><a href='#scroll-packages'>Packages & Pricing</a></li>
      </ul>
    </li>
    <li><a href='#scroll-faq'>FAQs</a></li>
    <li><a href='#'>Contact Us</a></li>
  </ul>
</div>
mplungjan
  • 169,008
  • 28
  • 173
  • 236

3 Answers3

0

Following code add the pipes between menu's

#container > ul > li {
    border-right: 1px solid black;
}
#container > ul > li:last-child {
    border-right: 0;
}
Hamza Zaidi
  • 672
  • 5
  • 8
0

Well thats because you have given every li a specific height here:

#container ul li {
  width: 130px;
  height: 30px;
  line-height: 30px;
  float: left;
  text-align: center;
  margin: 5px;
  border-radius: 0px;
}

Which does not let the box grow when its hovered. You can give the nav buttons that have the hovering option an id and give the following code:

#container ul li #drop_down{
  height: 100%;
}

For hindering future confusion, if you want to select direct children, use >, like so:

#container > ul {
  margin: 0px;
  padding: 0px;
  list-style-type: none;
  display: inline-block;
}

Here you have not used it, so even the inner ul is having these attributes, which ruins it. If you change it to the code above it will get fixed. Why? because the inner ul has the display: inline-block; attribute in your code which should not be.

Furthermore, Try giving the box a background-color and a z-index, so it will not keep detecting hover in behind boxes, in this case contact button.

For your other question I refer you to this link: How to make a vertical line in HTML

And, or: https://medium.com/@hollybourneville/creating-border-lines-using-pseudo-elements-in-css-a460396299e8

Amin Darian
  • 177
  • 2
  • 11
0

If I'm understanding you correctly, you want horizontal separators on your top-most navigation elements.

To do this, you can add borders to your li elements and then exclude the last one, like so:

#container ul li {
  // ... other styles here
  border-right: 1px solid black;
}

/* Add this additional style so that the last item doesn't receive the border */
#container ul li:last-child {
  border-right: none;
}

A working example can be found at https://codepen.io/BrandonClapp/pen/wvGqrmQ

Brandon Clapp
  • 66,931
  • 6
  • 20
  • 24