Horizontal dropdown menus offer a sleek alternative to traditional vertical dropdown layouts

How can I fix this issue with my drop-down menu? It looks fine until I hover over it and the menu turns horizontal instead of vertical. Could it be a CSS problem?

Thank you for your assistance!

JS Fiddle

HTML

<body> 
<div id="wrapper">
<div id="header"></div>
<nav id="mainnav"><img src="../images/Website/banner.jpg" width="1280" height="120">
 <ul style="list-style: none;">
      <li><a href="../index.html">Home</a></li>
      <li><a href="../research.htm">Research</a></li>
      <li><a href="../susantaylor.htm">Susan Taylor</a></li>
      <li><a href="../LaboratoryMembers.html">Lab Members</a>
          <ul>
                <li><a href="../currentmembers.htm">Current Members</a></li>
                <li><a href="../formermembers.htm">Former Members</a></li>
                <li><a href="../gallery.htm">Gallery</a></li>
          </ul>
      </li>
      <li><a href="../publications.htm">Publications</a></li>
      <li><a href="../links.htm">Links</a></li>
      <li><a href="../contact.htm">Contact Us</a></li>
</ul>
  </nav>

  <br>
 </br>
<div id= "content" align="center"> 
<br>
<div id="content-spacer-top"> </div>
    <div id="content-inner"> <!-- TemplateBeginEditable name="EditRegion3" --  >EditRegion3<!-- TemplateEndEditable --></div>
   <div id="content-space bottom"></div>

</div>
<footer class="footer" id="footer">
  <div align="center">
  <p>Taylor Laboratory<br> 
      Leichtag Biomedical Research Building
      4th Floor, Room 412
    <br>
    University of California, San Diego
    <br>
    9500 Gilman Dr. mc0654<br>
  La Jolla, CA 92093
  <br>
  Ph: (858) 534-8190
  <br>
  Fax: (858) 534-8193 </p>
</div>
</footer>


</div>


</body>

CSS li ul{ display:none; }

li:hover ul{
  display:block;
}
body {
    margin: 0px;
    background-color: #CCCCCC;
}
.content {
    background-color: #FFFFFF;
    padding-right: 6px;
    padding-left: 6px;
}
.footer {
    background-color: #357f7f;
    font-family: Arial, Helvetica, sans-serif;
    font-size: 8px;
    color: #FFFFFF;
    position: absolute;
}
#content {
    background-color: #FFFFFF;
    width: 100%;
    height: 100%;
    margin: 0 auto;
    min-height: 100%;
    height: auto;
}


a {
    text-decoration: none;
}
#wrapper {
    background-color: #FFFFFF;
    width: 1280px;
    min height: 100%;
    position: relative;
    height: auto;
    min-height: 100%
    margin-top: 0;
    margin-right: auto;
    margin-bottom: 0;
    margin-left: auto;
 }
#content-spacer-top {
    height: 10px;
}

#content-spacer-bottom{
    height:1%;
}

#header {
    background-color: #357f7f;
    height: 2%;
    width: 100%;
}
#mainnav a  {
    font-family: Arial, Helvetica, sans-serif;
    font-size: 16px;
    color: #000000;
    text-decoration: none;
    background-color: #FFFFFF;
    float: left;
    text-align: center;
    width: 14.28%;
    padding-top: 6px;
    padding-right: 0px;
    padding-bottom: 6px;
    padding-left: 0px;
    display: block;
    list-style-type: none;
    clear: none;
    margin: 0px;
    height: 2%;
    border-top-width: thin;
    border-right-width: thin;
    border-bottom-width: thin;
    border-left-width: thin;
    border-top-style: solid;
    border-right-style: none;
    border-bottom-style: solid;
    border-left-style: none;
    border-top-color: #357F7F;
    border-right-color: #357F7F;
    border-bottom-color: #357F7F;
    border-left-color: #357F7F;
}
#mainnav ul {
list-style-type: none;
margin: 0px;
padding: 0px;
}

#mainnav a:hover,#mainnav a:active,#mainnav a:focus {
color: #FFFFFF;
text-decoration: none;
background-color: #357F7F;
}
.style2 {
font-size: small;
color: #FFFFFF;
}

a:visited {
color: #FFFFFF;
background-color: #357F7F;
}
.style4 {font-size: x-small}
.style5 {background-color: #357f7f; font-family: arial;}
#footer {
width:1280px;
height:120px;
float:left;
font-family: Arial, Helvetica, sans-serif;
font-size: 10px;
text-transform: uppercase;
}

Answer №1

Upon reviewing your updated fiddle, it became evident to me that the issue was immediately apparent. Your code appears quite disorganized (apologies for being blunt) and contains numerous unnecessary CSS declarations.

Considering the poor state of your code, I took the liberty of creating a new fiddle with a functional navigation bar. You can find the relevant code below.

HTML:

<nav>
     <ul>
          <li><a href="../index.html">Home</a></li>
          <li><a href="../research.html">Research</a></li>
          <li><a href="../susantaylor.html">Susan Taylor</a></li>
          <li><a href="../LaboratoryMembelrs.html">Lab Members</a>
              <ul>
                    <li><a href="../currentmembers.html">Current Members</a></li>
                    <li><a href="../formermembers.html">Former Members</a></li>
                    <li><a href="../gallery.html">Gallery</a></li>
              </ul>
          </li>
          <li><a href="../publications.html">Publications</a></li>
          <li><a href="../links.html">Links</a></li>
          <li><a href="../contact.html">Contact Us</a></li>
    </ul>
</nav>

CSS:

nav {
    display: table;
    border-top: 1px solid #357F7F;
    border-bottom: 1px solid #357F7F;
}
nav ul {
    display: table-row;
    position: relative;
    margin: 0;
    padding: 0;
    z-index: 1;
}
nav ul a {
    display: block;
    color: black;
    text-decoration: none;
    padding: 10px 15px;
    font-family: Arial, Helvetica, sans-serif;
}
nav ul li {
    position: relative;
    display: inline-block;
    display: table-cell;
    width: 1%;
    list-style-type: none;
    text-align: center;
}
nav ul li:hover {
    background-color: #357F7F;
}
nav ul li:hover a {
    color: white;
}
nav ul ul{
    display: none;
    position: absolute;
    background: rgba(0,0,0,0.4);
    width: 100%; 
}
nav ul ul li {
    width: 100%;
    display: inline-block;
}
nav ul li:hover > ul {
    display: block;
}

JSFiddle

I trust this will be beneficial for you! :)

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Expanding using CSS3 to ensure it doesn't take up previous space

Currently, I am working on an animation for my web application. More specifically, I am looking to scale certain elements using CSS3 with the scaleY(0.5) property. These elements are arranged in a vertical list, and I want to ensure that they do not take u ...

What strategies and techniques should be considered when creating websites optimized for mobile devices?

With a wealth of experience in programming languages like Java, Python, and C, I actively engage in self-study to enhance my skills. While I have dabbled in creating mobile-friendly websites, upon reviewing my work, it is evident that my frontend developme ...

Issues with Image and Product Name Rendering in Outlook for Windows

Having a bit of trouble with Outlook PC not cooperating with my product images and names. While other email clients show the product names below the images as intended, Outlook PC is causing the names to appear next to the images like this - Product name ...

The <div> positioned at the highest point within its container

Looking to position a div at the top within its parent div, while leaving space below it unused. The default behavior appears to be the opposite, with the inner div dropping down to the bottom of its container and creating empty space above it. It seems l ...

Arrangement of Columns in Bootstrap 4 - Three Columns Aligned Vertically on the Left, One on the Right

My goal is to achieve a Bootstrap 4 layout like the one shown in the image linked below: https://i.sstatic.net/gY6m5.png For large devices, I want the Search Form, CTAs, and Button ads to be arranged vertically in a column that spans 4 units, while the C ...

Attempting to design a customized tooltip for an SVG element embedded within the HTML code

Recently, I've delved into Js with the goal of creating an interactive pronunciation guide using inline svg. If you're curious to see what I've done so far, check it out here. My current focus is on incorporating basic styled tooltips that ...

What is the best way to bring in this interface from the React-Particles-JS library?

I have been attempting to segregate my parameters from my JSX within the react-particles-js library. I organize my parameters in an Object: let config = { "particles": { "number": { "value": 50 }, ...

Instructions on utilizing Bootstrap Tags Input

I'm having issues with implementing the Markup from in my project. .bootstrap-tagsinput { background-color: #fff; border: 1px solid #ccc; box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075); display: block; padding: 4px 6px; color: #555 ...

Guide to positioning a link on the right side of a navigation bar

I am trying to achieve a specific layout using Bootstrap. I want to align the logout button to the right-hand side and have three modules (contact us, about epm, and modules) centered on the page. Can someone guide me on how to achieve this using Bootstr ...

When coding on Github pages, the behavior of code blocks can vary depending on whether

I am interested in obtaining the offline version, which can be seen here: https://i.sstatic.net/NKFSQ.jpg On the other hand, the online version has a different appearance: https://i.sstatic.net/133gH.jpg If you want to view the incorrect version, click ...

Failure to establish a viewport results in mobile devices displaying long lines with a bigger font size

Below is a code snippet that I am working with: <!doctype html> <html lang="en"> <head> <meta charset="UTF-8" /> <title>Document</title> </head> <body> ...

I haven't quite reached success yet, but I am working on getting my slideshow to display on my local server

My homepage is fully loading, but the slideshow feature is not functioning correctly. I have a file called slide.js in my /lib directory that I am trying to integrate into my homepage. The images are referenced properly and working, but they are not displa ...

Span tag not respecting CSS width property

One of my spans is causing an issue. Here are the styles in question: .form_container .col1che { float: left; width: 4%; text-align: left; } .form_container .col2che { float: left; width: 80%; text-align:left; } .form_container .col3che { float: ...

Postponing the initial display of a webpage

I am working with a web application from a different company that has some customization options limited to CSS and allows me to add HTML content at certain points in the code. However, I need more flexibility than what CSS can offer, so I have resorted t ...

Is there a way to format Persian words in a Left-to-Right direction?

When attempting to write Persian words in a left-to-right format for math formulas in a textarea using HTML and CSS, I am struggling to make it work with properties like direction:ltr;. I have tried various solutions but none have fixed the issue. I have ...

The Art of Div Switching: Unveiling the Strategies

I have a question regarding my website. I have been working on it for some time now, but I have encountered a challenge that I am struggling to overcome. After much consideration, I am unsure of the best approach to take. The issue at hand is that I have ...

Tips for effectively utilizing the jQuery closest method

This webpage allows me to upload images to a database and then display them again. When uploading an image, a comment can be added to it using a textarea. When the images are displayed again, the comments are shown and editable as well. Recently, I added a ...

Styling the background of the endAdornment in a material-ui textfield using React

I tried following the instructions from this source: Unfortunately, the example code provided doesn't seem to be functioning properly now. Is there a way to achieve the same result without having that right margin so that it aligns better with the r ...

Troubleshooting: Css navbar alignment

How can I center the navigation bar both horizontally and vertically? I've tried various methods but nothing seems to work. Here is my HTML: <section class="navigation" ng-controller="NavController"> <div class="nav-container"> ...

What sets minifying CSS apart from compressing CSS?

Recently, I was focused on enhancing my website's performance and decided to run a google developer performance test. The results were positive overall, but the google analyzer recommended compressing the CSS files for even better performance. Up unt ...