The CSS dropdown menu is malfunctioning on Internet Explorer and Firefox

After searching for a solution and coming up empty-handed, I have decided to ask a question. The drop-down menu on my computer and other devices at home works perfectly in Chrome but not in Firefox and IE.

#menu {
position: absolute;
left: 50%;  
bottom: 85.125%;
z-index: 100;

height: 100px;
margin-top: -200px;

width: 300px;
margin-left: -150px;
 }

 ul {
list-style-type: none;
padding: 0;
margin: 0;
 }

  ul#nav li {
background: #fff;
float: left;
  }

 ul#nav li a {
display: block;
text-decoration: none;
border-bottom: 1px solid #ccc;
color: #000;
padding: 5px 15px;
 }

 ul#nav li a:hover {
background: #aaa;
 }

 ul#nav li ul li {
float: none;
 }
 ul#nav li ul {
position: absolute;
display: none;
 }
 ul#nav li:hover ul {
display:block;
 }

 body {
margin: 0px;
padding: 0px;
  }




      <body>
        <header>
                <!-- input for header text-->
        </header>


        <div id="menu">
        <!-- input for the navigation menu -->
            <ul id="nav">
                <li><a href="hem.html" id="hem">Hem</a></li>

                <li>
                    <a href="#" id="browsers">Browsers</a>
                    <ul>
            <li><a href="chrome.html">Chrome</a></li>
            <li><a href="firefox.html">Firefox</a></li>
            <li><a href="ie.html">IE</a></li>
            <li><a href="opera.html">Opera</a></li>
                    </ul>
                </li>

            <li><a href="data.html" id="data"> Data</a></li>
            <li><a href="synpunkt.html" id="synpunkt">Synpunkt</a></li>
            </ul>

        </div>
   </body>

Answer №1

Here are two reasons why your code may not be working correctly:

1) There seems to be an error in your HTML. The lines --

    <li><a>href="chrome.html">Chrome</a></li>
    <li><a>href="firefox.html">Firefox</a></li>

should actually be

    <li><a href="chrome.html">Chrome</a></li>
    <li><a href="firefox.html">Firefox</a></li>

And

2) It appears that your ul has id navbar, but in the CSS you're using #nav as the selector. You will need to either change the ID or update the selector in the CSS.

Please review the Test Link for more information.

EDIT: Screenshots included below for reference:

Firefox:

IE9:

If these suggestions do not resolve the issue, please provide further details on what is incorrect.

Answer №2

Looks like there's an issue with your HTML:

        <li><a>href="chrome.html">Chrome</a></li>
        <li><a>href="firefox.html">Firefox</a></li>

The correct format should be:

        <li><a href="chrome.html">Chrome</a></li>
        <li><a href="firefox.html">Firefox</a></li>

I'm still having trouble getting it to work in Chrome. Could you try replicating the issue on JSFiddle?

Answer №3

For optimal display, utilize the following CSS code and ensure compatibility with Internet Explorer 9 by setting both browser mode and document mode to IE9.

UPDATE: The header should have this appearance.

<!doctype>
<html>
<head>
    <meta charset=utf-8>
    <title>Index</title>
    <link rel="stylesheet" href="css/style.css">
</head>

#menu 
     {
         position: relative;
         top: 50px;
         left: 800px;
         display: inline-block;
     }

ul 
    {

list-style-type: none;
        padding: 0;
        margin: 0;
    }

ul#nav li 

    {
        background: #fff;
        float: left;
        position: relative;
    }

ul#nav li a 

    {
        display: block;
        text-decoration: none;
        border-bottom: 1px solid #ccc;
        color: #000;
        padding: 5px 15px;
    }

ul#nav li a:hover 

    {
        background: #aaa;
    }

ul#nav li > ul li 

    {
        float: none;
    }

ul#nav li > ul 

    {
        left: 3px;
        position: absolute;
        top: 29px;
        display: none;
    }

ul#nav li:hover ul {
        display:block;
    }

body 

    {
        margin: 0px;
        padding: 0px;
    }

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

Customizing Material UI Themes

Is there a way to customize the MuiTheme overrides for a specific named element like this? .MuiStepLabel-label.MuiStepLabel-active { color: rgba(0, 0, 0, 0.87); font-weight: 500; I've attempted modifying various classes such as MuiStepLabelLa ...

How can the onclick attribute be modified in an HTML document?

I am looking to update the data-pro-bar-percent attribute of a progress bar from 80 to 100 when a specific link is clicked. The change in attribute needs to be as follows: data-pro-bar-percent="80" --> data-pro-bar-percent="100" This is the current HT ...

Using PHP variables in JavaScript to access getElementById

I have multiple forms displayed on a single PHP page. They all follow a similar structure: <form id="test_form_1" action="test_submit.php" method="post" name="test_form"> <label>This is Question #1:</label> <p> &l ...

Troubleshooting: Select2 Search Functionality Error

After working with the select2 plugin for some time, everything seemed perfect until now. I have a page with 3 selects that load data and function properly, as well as multiple selects inside a popup. The appearance is good, but the search field is not al ...

Tips for selecting an <select> option value based on an URL parameter automatically

I have a 2-step form where I am successfully passing the first name in the URL from step 1 to step 2, but I am struggling to do the same for a select field. Here's an example of what I have: In the URL: ?firstname=Bob Form Field: <input type= ...

Is there a way to change the font size with a click in JavaScript or Angular?

Here is a breakdown of the 4 steps: 1.) Begin by clicking on a category 2.) The filtered products will be displayed 3.) Select the desired products from the filter 4.) Once selected, the products will appear in the rightmost part of the screen within t ...

Troubleshooting Bootstrap 4 Content Alignment Issue: Centering Horizontally and Vertically

Having trouble centering my content both vertically and horizontally within the body of the webpage using Bootstrap 4. Despite trying various solutions from the documentation and StackOverflow, I can't seem to get it to work. Would greatly appreciate ...

Angular not firing slide.bs.carousel or slid.bs.carousel event for Bootstrap carousel

I've searched high and low with no success. I'm attempting to detect when the carousel transitions to a new slide, whether it's automatically or by user click. Despite my numerous attempts, I have been unable to make this event trigger. I ha ...

Guide to implementing an ES6 template within an HTML anchor tag href

Hello there, this is my first time seeking assistance here. I have an ajax request returning a JSON response. Now, I am aiming to use the response data to dynamically generate recipe titles and also create clickable links with that data. $( window ).load( ...

Guide on modifying CSS properties when hovering over the parent element

I am working with a table structure like this: <table> <tr><td class="momdad"><i class='glyphicon glyphicon-cog'></i> Hello </td><td> Mom </td></tr> <tr><td class="momdad">< ...

Detecting Specific Web Browsers on My Website: What's the Best Approach?

My website is experiencing compatibility issues with certain browsers, such as Firefox. I want to display a message when users visit the webpage using an unsupported browser, similar to how http://species-in-pieces.com shows a notification saying "Works ...

Having trouble with Jquery not working, and I'm stumped trying to solve it

I wrote this function but I can't figure out why it's not working. The JS file is being loaded because other functions inside it are functioning properly, but those with this specific format aren't: $(function () { .... }); The intention ...

The ion-range slider does not function properly when trying to display a central label

After customizing the ion range slider to suit my needs, I am looking for some simple functionalities: 1. The label should be centered. 2. When clicking on the label, the handle should move accordingly. 3. There should be a color gap between two valu ...

What steps can be taken to create a two-column layout using the provided HTML code?

I'm having trouble getting my CSS to work properly in IE 8. Any suggestions on how to fix this? Here's the simplified HTML code I'm using: <div id="column-content"> <div id="content"> <p>This is some text</ ...

Selecting multiple objects in FabricJS on mouse click

Can anyone provide suggestions on how to select multiple objects on a canvas with a mouse click? I only want to select objects that overlay the point. From my understanding, the target of the mouse event is always the top-most object. I have tried binding ...

How can I use JavaScript to capture the "MDCMenu:selected" event for the Menu Component in Material Design Web Components?

I am currently using the Material Design Web Components plugin known as "Menu." Once the menu is launched, my goal is to be able to effectively handle all possible ways a "menu item" can be selected. While adding an on-click event through my framework&apo ...

How to extract selected value from a dropdown menu in a React component

Is there a way for me to retrieve the chosen value from the dropdown menu? The select dropdown contains 12 options. My goal is to capture the selected value and then utilize it in handlecolumnchange to manipulate the number of columns added or removed. Des ...

JavaScript - continuously update the image marked as "active"

I have a collection of 4 pictures that I want to rotate through in my web application. Each picture should have the "active" class applied to it, similar to when you hover over an image. .active, .pic:hover{ position: absolute; border: 1px solid ...

Customize CSS class in ASP.Net

Here's the CSS code I am currently using: LinkButton:hover { color:White; background-color:Gray; } .myClass { color:Blue; } The issue I'm facing is that I have a LinkButton with the CssClass .myClass, and when I hover over it, the b ...

Is there a way to dynamically expand and collapse all table rows, with the latest row always remaining visible, using pure JavaScript?

I have a form input field where I enter data. The entered data is then displayed in a table as a new row, with the most recent entry at the top. What I want to achieve is to show only the newest row in the table and hide all other rows. When I hover over ...