Broken CSS dropdown menu issue

Recently, I encountered an issue with a hoverable drop-down menu that has been functioning smoothly for years. After adding a new sub link, the code broke.

Here is the code for the menu:

#divMenu, ul, li, li li {
  margin: 0;
  padding: 0;
}
#divMenu {
  width: 150px;
  height: 27px;
}
#divMenu ul {
  line-height: 50px;
}
#divMenu li {
  list-style: none;
  position: relative;
  background: #cfcfcf;
  font-size:20px;
}
#divMenu li li {
  list-style: none;
  position: relative;
  background: #C0C0C0;
  left: 148px;
  top: -27px;
  font-size:12px;
  z-index: 999;
}
#divMenu ul li a {
  width: 148px;
  height: 40px;
  display: block;
  text-decoration: none;
  text-align: center;
  font-family: Georgia,'Times New Roman',serif;
  color:#000000;
  border:1px solid #2d2d2d;
}
#divMenu ul ul {
  position: absolute;
  visibility: hidden;
  top: 27px;
}
#divMenu ul li:hover ul {
  visibility: visible;
}
#divMenu li:hover {
  background-color: #C0C0C0;
}
#divMenu ul li:hover ul li a:hover {
  background-color: #C0C0C0;
}
#divMenu a:hover {
  font-weight: none;
}
<div id="divMenu">
  <li><a href="index.php">Etusivu</a></li>
  <li><a href="kissala.php">Kissala</a></li>
  <li><a href="mainecoon.php">Maine Coon</a></li>
  <li><a href="#">Herrat</a>
    <ul>
      <li><p style="font-size:10px;margin:0px"><a href="hermann.php">Macawi 
    Mosi Double E´s Xahir</a></p></li>
      <li><a href="leo.php">Vuorensinen Baloo</a></li>
    </ul>
  </li>
  <li><a href="#">Ladyt</a>
    <ul>
      <li><a href="sura.php">Blackcurrant Sophia Loren</a></li>
    <li><a href="hilde.php">Bloomingtree QQ`Sweetest Taboo</a></li>
    </ul>
  </li>
  <li><a href="#">Kastraatit</a>
    <ul>
      <li><a href="luna.php">Artsycats Lucy In The Sky</a></li>
    </ul>
  </li>
  <li><a href="#">Pennut</a>
    <ul>
      <li><a href="varattavissa.php">Varattavissa</a></li>
      <li><a href="suunnitelmat.php">Suunnitelmat</a></li>
    <li><a href="pentuinfo.php">Pentuinfo</a></li>
    </ul>
  </li>
  <li><a href="#">Pentueet</a>
    <ul>
      <li><a href="vintagestar.php">Vintage Star -pentue</a></li>
    <li><a href="oldwest.php">Old West -pentue</a></li>
    </ul>
  </li>
  <li><a href="linkit.php">Linkit</a></li>
  <li><a href="yhteystiedot.php">Yhteystiedot</a></li>
  <li><a href="http://users4.smartgb.com/g/g.php?a=s&i=g44-74607-
  71">Vieraskirja</a></li>
</ul>
</div>

Upon adding a new sub-link, the code malfunctioned. Even after removing it, the issue persisted.

https://i.sstatic.net/MCLOg.jpg

Screenshot: all sub-links are displayed at all times - they do not hide when hovering

Answer №1

Please ensure to include the <ul> tag right after <div id="divMenu">. Adding this tag will help resolve the issue.

#divMenu, ul, li, li li {
  margin: 0;
  padding: 0;
}
#divMenu {
  width: 150px;
  height: 27px;
}
#divMenu ul {
  line-height: 50px;
}
#divMenu li {
  list-style: none;
  position: relative;
  background: #cfcfcf;
  font-size:20px;
}
#divMenu li li {
  list-style: none;
  position: relative;
  background: #C0C0C0;
  left: 148px;
  top: -27px;
  font-size:12px;
  z-index: 999;
}
#divMenu ul li a {
  width: 148px;
  height: 40px;
  display: block;
  text-decoration: none;
  text-align: center;
  font-family: Georgia,'Times New Roman',serif;
  color:#000000;
  border:1px solid #2d2d2d;
}
#divMenu ul ul {
  position: absolute;
  visibility: hidden;
  top: 27px;
}
#divMenu ul li:hover ul {
  visibility: visible;
}
#divMenu li:hover {
  background-color: #C0C0C0;
}
#divMenu ul li:hover ul li a:hover {
  background-color: #C0C0C0;
}
#divMenu a:hover {
  font-weight: none;
}
<div id="divMenu">
<ul>
  <li><a href="index.php">Etusivu</a></li>
  <li><a href="kissala.php">Kissala</a></li>
  <li><a href="mainecoon.php">Maine Coon</a></li>
  <li><a href="#">Herrat</a>
    <ul>
      <li><p style="font-size:10px;margin:0px"><a href="hermann.php">Macawi 
    Mosi Double E´s Xahir</a></p></li>
      <li><a href="leo.php">Vuorensinen Baloo</a></li>
    </ul>
  </li>
  <li><a href="#">Ladyt</a>
    <ul>
      <li><a href="sura.php">Blackcurrant Sophia Loren</a></li>
    <li><a href="hilde.php">Bloomingtree QQ`Sweetest Taboo</a></li>
    </ul>
  </li>
  <li><a href="#">Kastraatit</a>
    <ul>
      <li><a href="luna.php">Artsycats Lucy In The Sky</a></li>
    </ul>
  </li>
  <li><a href="#">Pennut</a>
    <ul>
      <li><a href="varattavissa.php">Varattavissa</a></li>
      <li><a href="suunnitelmat.php">Suunnitelmat</a></li>
    <li><a href="pentuinfo.php">Pentuinfo</a></li>
    </ul>
  </li>
  <li><a href="#">Pentueet</a>
    <ul>
      <li><a href="vintagestar.php">Vintage Star -pentue</a></li>
    <li><a href="oldwest.php">Old West -pentue</a></li>
    </ul>
  </li>
  <li><a href="linkit.php">Linkit</a></li>
  <li><a href="yhteystiedot.php">Yhteystiedot</a></li>
  <li><a href="http://users4.smartgb.com/g/g.php?a=s&i=g44-74607-
  71">Vieraskirja</a></li>
</ul>
</div>

Answer №2

Make sure to include the opening element ul at the beginning of your HTML code. Here is the corrected version:

<div id="divMenu">
        <ul>
            <li><a href="index.php">Etusivu</a></li>

            <li><a href="kissala.php">Kissala</a></li>

            <li><a href="mainecoon.php">Maine Coon</a></li>

            <li>
                <a href="#">Herrat</a>
                <ul>
                    <li>
                        <p style="font-size:10px;margin:0px">
                            <a href="hermann.php">
                                Macawi
                                Mosi Double E´s Xahir
                            </a>
                        </p>
                    </li>
                    <li><a href="leo.php">Vuorensinen Baloo</a></li>

                </ul>
            </li>
            <li>
                <a href="#">Ladyt</a>
                <ul>
                    <li><a href="sura.php">Blackcurrant Sophia Loren</a></li>
                    <li><a href="hilde.php">Bloomingtree QQ`Sweetest Taboo</a></li>
                </ul>
            </li>

            <li>
                <a href="#">Kastraatit</a>
                <ul>
                    <li><a href="luna.php">Artsycats Lucy In The Sky</a></li>
                </ul>
            </li>

            <li>
                <a href="#">Pennut</a>
                <ul>
                    <li><a href="varattavissa.php">Varattavissa</a></li>
                    <li><a href="suunnitelmat.php">Suunnitelmat</a></li>
                    <li><a href="pentuinfo.php">Pentuinfo</a></li>
                </ul>
            </li>

            <li>
                <a href="#">Pentueet</a>
                <ul>
                    <li><a href="vintagestar.php">Vintage Star -pentue</a></li>
                    <li><a href="oldwest.php">Old West -pentue</a></li>
                </ul>
            </li>

            <li><a href="linkit.php">Linkit</a></li>
            <li><a href="yhteystiedot.php">Yhteystiedot</a></li>
            <li>
                <a href="http://users4.smartgb.com/g/g.php?a=s&i=g44-74607-
71">Vieraskirja</a>
            </li>
        </ul>
    </div>

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

Subnav sticks when scrolling down but becomes unresponsive on resizing

My webpage has a main header that sticks to the top of the window and a subnav fixed at the bottom. The hero image adjusts its height based on the window minus the header and subnav heights. When scrolling past the subnav, it sticks just below the main nav ...

Designing a webpage feature that enables users to choose an image from the selection

Can someone help me with coding a feature on my page where users can simply click an image to select their favorite design? I want the selection to be recorded and sent to me without requiring any text input from the user. I plan to use jQuery to display t ...

Ways to extract innerHTML content from a loaded element generated by using the .load() method

Check out the code snippet below: template.html : <div id="nav"> Welcome to Space </div> layout.html : <div id="content"> </div> $('#content').load("template.html #nav"); ale ...

Creating a slanted polygon div that adjusts to different screen sizes: a step-by-step

Looking to create a slanted and responsive div similar to the example image provided. Any assistance would be greatly appreciated. ...

Creating AngularJS variables with dependencies on integer values

Hello, I am a brand new developer and I am currently working on creating an expenses calculator. The goal is to have the sum of inputted integers from a table, each with a default value, become the integer value of another variable. However, I seem to be m ...

Include a scrollbar within a Bootstrap table grid under a div with a width of 12 columns

How can I add a scrollbar to the grid below? It is using a bootstrap table inside a bootstrap col 12 div. I have attempted to use the following CSS, but it does not apply a scrollbar, it only disrupts the columns. divgrid.horizontal { width: 100%; ...

**Issue Resolved:** Looking to have the form results appear only when a valid input is submitted; otherwise, the

As a newcomer to PHP, SQL, and HTML, I've been learning for around 3 months now. Can someone assist me in achieving the following: I would like my form to display the results table only if a valid search has been submitted, showing only the database r ...

What's causing all my carousel slides to stack on top of each other instead of presenting in a

Whenever I click 'run' or 'preview' in a browser, specifically using Chrome, all three slides are displayed stacked from 1 to 3 in a static view. They do not toggle through each slide as intended. This issue only occurs on Codeply, a p ...

Fade out at varying speeds

As I delve into CSS3 animations, I have been experimenting with some example code. Here is the link to the code: http://jsfiddle.net/chricholson/z7Bg6/67/ I am curious about how to adjust the duration of animations when un-hovering. Currently, it seems th ...

CSS Style for Organizing Content

I'm struggling to create CSS for a hierarchical display, resembling a tree structure of files and folders. Currently, I am using nested unordered lists in my HTML: <ul> <li>animals<ul> <li>dogs</li> <li>c ...

Demonstrate HTML and CSS integration through the use of the http.get method

In an attempt to create an iframe-like solution, I am using an http.get call to retrieve a site as an object containing HTML and CSS. The issue arises when using <link> tags because the CSS path is obtained from an external source, causing the HTML t ...

What is the best way to personalize the icon for this navigation button?

I'm interested in making some changes, especially to the border. I've already figured out how to adjust the color of the 3 bars like so: .navbar-default .navbar-toggle .icon-bar { background-color: #fff; } Modification RESOLUTION .navbar- ...

What's the best way to modify HTML element classes using Javascript?

I have designed a custom cms theme with various customization options that I wish to showcase in a live demo. My goal is to implement Javascript style switchers or modifiers where users can choose values from checkboxes or select tags, and see their select ...

When the user clicks the back button in AngularJS

After searching extensively, I have yet to find a straightforward solution to my issue. The problem lies in a search/filter field that filters the page based on user input. While this filter works efficiently, it clears whenever a navigation item is clicke ...

What is the method to integrate PHP with HTML code?

Apologies if this question has been asked before, but I have not found anyone with the same query as mine. I am new to HTML and PHP, and I am looking to enhance my skills by creating a registration form and storing all the data in a MySQL database using XA ...

What is the most creative way you can think of to create a CSS/JS animated

Is using an animated SVG the best way to create these wavy blobs for mobile compatibility? What approach would you take? Here is a similar example I found var wave = document.createElement("div"); wave.className += " wave"; docFrag.appendChil ...

What separates text-align:center from margin auto?

As someone who is just beginning to learn about CSS, I have come across the properties: text-align:center; and margin:auto; Both of these seem to center elements, but how exactly do they differ from each other? Any insights would be much appreciated. T ...

Position the flex item adjacent to the initial flex item using wrap mode only if there is extra space

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta http-equiv="X-UA-Compatible" content="ie=edge" /> <titl ...

Trouble in connecting local CSS stylesheet

I am facing an issue with adding my .css file to my project. Even though I have tried various methods, the styles are not being applied properly. When I directly embed the style code in HTML, it seems to work fine. This leads me to believe that the proble ...

Enhance the appearance of Font Awesome stars by incorporating a hover effect

Is there a straightforward way to make them turn solid yellow when you hover over them? const styles = theme => ({ root: { flexGrow: 1, overflow: 'hidden', padding: theme.spacing(0, 3), }, paper: { maxWidth: 800, mar ...