Issue with dropdown menu display in Internet Explorer

Having trouble with a CSS dropdown menu displaying incorrectly in IE, while working fine on other browsers.


    <body>
<div id="container">
    <header>        
        <div id="hlogo">
            <a href="index.html">title</a>
        </div>
        <nav id="hmenu">
            <ul>
                <li>
                    <a href="menu1.html">menu1</a>
                </li>
                <li>
                    <a href ="menu2.html">menu2</a>
                    <div id="items" class="hiddenMenu">
                        <a href="submenu1.html">submenu1</a>
                        <a href="submenu2.html">submenu2</a>
                        <a href="submenu3.html">submenu3</a>
                        <a href="submenu4.html">submenu4</a>
                    </div>
                </li>
                <li>
                    <a  href ="menu3.html">menu3</a>
                </li>
                <li>
                    <a  href ="menu4.html">menu4</a>
                </li>
            </ul>
            </nav>
    </header>

    <section id="container-body">
        <div id="content">



        </div>
    </section>
</div>  

This is the HTML markup I'm using along with the following CSS styling.


    /* layout styles */
*{margin:0;padding:0;font-family:Arial;}
header{overflow:hidden;}
body{background-color:#cc3333;}
a {display: inline-block;font-weight: bold;text-decoration:none;}

footer {
    display:block;
    position:relative;
    width:100%;
}
footer > #disclamer {

    margin-left: auto;
    margin-right: auto;
    width: 200px;
    padding-bottom:5px;
    font-size:small;
    font-weight: bold;
}
#container{
    background-color:#ffffff;
    margin:auto;
    min-width:756px;
    width:60%;
    overflow:hidden;
    border:solid 2px #666666;
    margin-top:10px;
    margin-bottom:10px;
    box-shadow:0 1px 3px rgba(0,0,0,0.6);
}

#hlogo {float:left;height:105px;width:181px;padding:10px;}
#hlogo a{background-position: 0px 0px;float:left;display:inline;height:105px;text-indent:-999999em;width:181px;}
#hlogo a{background-image:url('../images/logo.png');background-repeat:no-repeat;overflow:hidden;}

#hmenu{margin-top:45px;padding:10px;}

nav {
    list-style:none;
    display:inline;
    float:right;
}
nav ul{
    list-style: none;
    text-align:center;
    background-color:#666666;
    float:left;

}
nav ul li {
    width:128px;
    float:left;
    display:inline-block;
}
nav ul li:hover{
    background-color:#cc3333;
    cursor:pointer;
}
nav ul li a {
    color:#ffffff;
    padding:10px;
}

nav ul {
    background: #222 url('../images/overlay.png') repeat-x;
    color: #fff;
    text-shadow: 0 -1px 1px rgba(0,0,0,0.25);
    cursor: pointer
}

section {margin:10px;}

#container > header {display:block;}

#container-body {
    background-color:#ececec;
    height:600px;
    display:block;
    overflow:auto;
}

#container-body  > #content {
    margin: 10px;
    height:95%;
    position:relative;
}
    .hiddenMenu 
{
    position:absolute;
    z-index: 150;
    background: #222 url('../images/overlay.png') repeat-x;
    color: #fff;
    text-shadow: 0 -1px 1px rgba(0,0,0,0.25);
    cursor: pointer;
    width: inherit;
}
.hiddenMenu > a
{
    position:relative;
    text-align: left;
    clear:both; 
    font-size:0.75em;   
}


nav li .hiddenMenu > a
{
    display:none;
}
/*nav li:hover .hiddenMenu  > a
{
    display:block;
}*/

nav li .hiddenMenu  > a:hover
{
    background-color:#cc3333;   
    cursor:pointer;
    border: 1px black solid;
}

The menu works as expected on Firefox but not on IE, showing only the first submenu item and then disappearing. Any ideas on how to fix this issue would be greatly appreciated!

Edit: Added code snippets for better understanding of the situation.

One workaround could be changing the overflow property from hidden to visible on the header tag, though it might impact the overall layout. Are there any alternative solutions or am I missing something?

Additionally, a jQuery script manages the menu's display behavior, which seems to fail on IE when hovering over submenu items. Why does this occur despite the script being properly implemented?

Answer №1

From my personal experience, I have found that Internet Explorer tends to become glitchy if you do not specify the positions of an absolutely positioned object, such as setting top: 0 and left: 0.

Additionally, the parent of the absolutely positioned object should have position: relative if the position is supposed to be based on the parent's dimensions.

It seems that li:hover does not function properly in IE6, possibly also in IE7. One of them only accepts a:hover, and browsers lower than that might not recognize either. This issue can be resolved using jQuery.

Regarding nav elements: I am not familiar with the navigation stuff, as I have not transitioned to HTML5 yet. Nevertheless, I have managed to create something functional based on your code.

Here is the script (using jQuery):

$(document).ready(function () {
  $('#hmenu ul li').hover(function () {
    $(this).children('div').css('display', 'block');
  },
  function () {
    $(this).children('div').css('display', 'none');
  });
});

CSS styling:

#hmenu {
    list-style: none;
    display: inline;
    float: right;
}

#hmenu ul {
    list-style: none;
    text-align: center;
    background-color: #666666;
    float: left;
}

#hmenu ul li {
    width: 128px;
    float: left;
    position: relative;
    display: inline-block;
}

#hmenu ul li:hover {
    background-color: #cc3333;
    cursor: pointer;
}

#hmenu ul li a {
    color: #ffffff;
    padding: 10px;
}

#hmenu ul {
    background: #222 url('../images/overlay.png') repeat-x;
    color: #fff;
    text-shadow: 0 -1px 1px rgba(0, 0, 0, 0.25);
    cursor: pointer
}

.hiddenMenu {
    display: none;
    position: absolute;
    top: 60;
    left: 0;
    z-index: 150;
    background: #222 url('../images/overlay.png') repeat-x;
    color: #fff;
    text-shadow: 0 -1px 1px rgba(0, 0, 0, 0.25);
    cursor: pointer;
    width: inherit;
}

(Apologies for the formatting, still getting used to it. You can adjust the source formatting in your editor. I modified the IDs of the navigation elements and changed the HTML navs to divs. That's all.

HTML structure:

<div id="hmenu">
    <ul>
        <li>
            <a href="menu1.html">menu1</a>
        </li>
        <li>
            <a href="menu2.html">menu2</a>
            <div id="items" class="hiddenMenu">
                <a href="submenu1.html">submenu1</a>
                <a href="submenu2.html">submenu2</a>
                <a href="submenu3.html">submenu3</a>
                <a href="submenu4.html">submenu4</a>
            </div>
        </li>
        <li>
            <a href="menu3.html">menu3</a>
        </li>
        <li>
            <a href="menu4.html">menu4</a>
        </li>
    </ul>
</div>

Answer №2

It is not possible to use a tag called nav. Please replace it with div and attempt the task once more.

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

Is it possible to swap images by clicking on them?

Let's say I'm working with 3 images. Image A, B and C. A is the main image initially. If I click on image B, it will become the main image and image A will take its place in the old position. The same condition applies when B is the main image a ...

Using Paper Checkbox to Toggle the Visibility of a Div in Polymer

Having experience with Meteor, I typically used JQuery to toggle the display of a div along with paper-checkbox: HTML: <paper-checkbox name="remoteLocation" id="remote-chk" checked>Remote Location</paper-checkbox> <div id="autoUpdate" clas ...

Adjusting the tab size and space size to their default settings within VSCode

I'm currently facing an issue with my VSCode setup. I am trying to configure the space size to be equal to 1 and tab size to be equal to 2 as the default for every project. However, despite my efforts, it keeps reverting back to spaces: 4 for each new ...

The jQuery click function triggers immediately upon the loading of the page

Despite my best efforts to resolve this issue independently and conduct extensive research on Google, I am still unable to identify the root of the problem. It seems that the click function continues to activate upon page load. Kindly elucidate the under ...

Alternating row colors using CSS zebra striping after parsing XML with jQuery

After successfully parsing XML data into a table, I encountered an issue with applying zebra stripe styling to the additional rows created through jQuery. Despite my efforts to troubleshoot the problem in my code, I remain perplexed. Below is a snippet of ...

Exploring color options in matplotlib for HTML designs

Is there a way to change color in a matplotlib plot using html in Python? I attempted plt.plot(x,y,marker=".",color="#e0e0e0") However, this resulted in data points displayed as ".", connected by lines of color #e0e0e0 which is not desired. I also experi ...

Sibling proximity: an excess of elements separating the regulations

Is there a way to make a hidden p element appear when hovering over the first visible element in a tree structure? I found some help on Stack Overflow suggesting the use of adjacent sibling selectors, and while it works well with a simple example, it fails ...

Modifications to contenteditable elements result in a change to their IDs

Having some trouble with the behavior of a contenteditable div. The code structure is like this: <div contenteditable="true"> <p id="element-id-1">element-id-1</p> <p id="element-id-2">element-id-2</p> </div> E ...

Superior method to ensure the child element's border overlaps with that of the parent

I am currently working on a project that requires a unique CSS effect: Let me explain exactly what I am trying to achieve: The main element (referred to as the title) has padding and a 2px bottom border. Inside this, there is a child element (known as ti ...

Updating the underline style of ant.d's menu item

Currently, I am working with ant.design to build my navbar. By default, the menu items in ant design have a blue-ish underline when selected or hovered over. However, I want to change this underline color to match the overall design of my project. I was su ...

Error found - PHP if condition inside HTML td element

Whenever I open my browser, I encounter this error message: Parse error: syntax error, unexpected 'if' (T_IF) I have been working on creating an HTML table to display prices for a Woocommerce product. Although I've come across similar issu ...

How can I ensure my screen updates instantly after modifying an image's source using Javascript?

My goal is to display a new image in an existing <img> tag by updating the src attribute using JavaScript. The issue I'm facing is that the screen doesn't immediately reflect the change when the src is updated with the URL of a thumbnail im ...

What is the best way to create a button that can show or hide an unordered list with a click?

This is where you can find my special button: <body> <h3 class="paragraph">To remove duplicates in 2 Javascript arrays (refer to the readme), combine the results into a new array and display the unique names in an unordered list below ...

Adjust the appearance of elements depending on whether the user has activated dark mode or

What is the most efficient way to implement both dark and light themes in my Vue app? One option is to create a 'dark.scss' file and use the '!important' property to override styles defined in components. Another option is to utilize pr ...

Extracting information from an external website in the form of XML data

Trying to retrieve data from an XML feed on a remote website , I encountered issues parsing the XML content and kept receiving errors. Surprisingly, fetching JSON data from the same source at worked perfectly. The code snippet used for XML parsing is as f ...

Personalized parallax design

I am in the process of developing my own custom parallax plugin to allow me to control the direction in which items transition off the screen. However, I am currently facing a challenge in ensuring that regardless of how a user scrolls or the size of the w ...

Preventing context menu from appearing on a right click by implementing a trigger to re-enable it

I am looking to implement a functionality on my website that disables the right click menu. Currently, I have achieved this through the following code: document.addEventListener("contextmenu", function(e){e.preventDefault(); }, false); Now, I am wonderin ...

Eliminate any iframes that have a src attribute with the value of "some_src.com/....."

I'm brand new to coding in javascript. I've noticed that there is an annoying ad popup that manages to sneak through Adblock super without being detected. It's driving me crazy and I want to block it! Here's the code for the iframe: IF ...

html - displaying a new page within the content of the current page

I have a question about basic HTML knowledge that I find embarrassing Is it possible to open or load a second page within my first page? I want a menu button that will load the second page. <li class="current"><a href="first.html" target = "myC ...

Incorporate a horizontal scrollbar feature within an HTML section

Currently, I am in the process of learning vue js and would like to create a layout that includes two sections. The first section should occupy 3 grids on the screen, be fixed, and not scrollable, with a division into 4 vertical parts. The second section s ...