Trouble with CSS submenus: Are your lists not appearing as they should? Potential style override

I am encountering an issue with my dropdown mega menu. I have two sets of list items that should be displayed vertically side by side with bullet points in the dropdown, but only one list is appearing despite coding for both.

Additionally, the list elements are changing to black and white on hover instead of the desired white normally and black on hover. The bullet points for each list element are also not displaying, likely due to conflicting styles overriding each other.

Any assistance with resolving these issues would be greatly appreciated. Thank you.

Example fiddle: http://jsfiddle.net/DannyW86/8krqjjj7/6/

HTML:

<div id="hdr-box">
            <a href="#"><div id="logo"></div></a>

            <nav class="mainnav">
                <ul>
                    <li><a href="#">New Cars</a></li>
                    <li><a href="#">Used Cars</a></li>
                    <li><a href="#">Servicing</a>
                        <div class="mega-menu">
                            <img src="img/servicing.png" />
                            <h3>Servicing</h3>
                            <p>Lorem Ipsum dolor sit amet, consectetur adipiscing elit, Ut ul tempus tellus.</p>
                            <div id="sub-nav">
                                <ul>
                                    <li><a href="#">Book a sevice Online</a></li>
                                    <li><a href="#">Express Service</a></li>
                                    <li><a href="#">BMW</a></li>
                                    <li><a href="#">Dacia</a></li>
                                    <li><a href="#">Hyundai</a></li>
                                    <li><a href="#">Lexus</</li>
                                </ul>
                            </div>
                            <div id="sub-nav">
                                <ul>
                                    <li><a href="#">MINI</a></li>
                                    <li><a href="#">Motorrad</a></li>
                                    <li><a href="#">Nissan</a></li>
                                    <li><a href="#">Renault</a></li>
                                    <li><a href="#">Toyota</a></li>
                                </ul>
                            </div>
                        </div><!-- End of mega menu  -->

                    </li>
                    <li><a href="#">Finance</a></li>
                    <li><a href="#">Accessories</a></li>
                </ul>
            </nav><!-- End of mainnav -->
        </div>

CSS:

#hdr-box {
width: 100%;
display: inline-block;
}

#logo {
width: 361px;
height: 90px;
background: url(../img/logo.png) no-repeat;
float: left;
}

.mainnav {
/*font-family: "Myriad Pro", 'PT Sans Caption', sans-serif;*/
font-size: 20px;
}

#hdr-box nav {
line-height: 30px;
margin: 30px auto 0 auto;
text-align: center;
width: 563px;
float: right;
margin-right: 50px;
}

#hdr-box nav ul {list-style: none; margin: 0 auto; width: 800px;}
#hdr-box nav li {float: left; display: inline; margin-right: 40px;}

#hdr-box nav a,  #topbar nav a:visited{
color: #000;
display: inline-block;
text-decoration: none;
}

#hdr-box nav a:hover {
color: #02a2e0;
}

nav li > .mega-menu {
font-family: Arial, Helvetica, sans-serif;
font-size: 14px;
color: #fff;
width: 770px;
height: 204px;
padding: 40px;
background: #02a2e0;
visibility: hidden;
/*display: none;*/
overflow: hidden;
position: absolute;
right: 200px;
z-index: 99999;
text-align: left;
list-style: disc;
}

nav li:hover > .mega-menu {
visibility: visible;
display: block;
}

.mega-menu img {
float: left;
margin-right: 30px;
width: 272px;
height: 207px;
}

.mega-menu h3 {
color: #fff;
font-size: 18px;
}

#mainnav ul.mega-menu ul {
display: none;
position: absolute;
left: 0;
}

#mainav ul.mega-menu li { display: block!important;}


.mega-menu p {line-height: 23px;}

.nav-column {width: 135px}

#sub-nav ul li {
float: none ;
display: block ; 
}

Answer №1

There are several issues that need to be addressed here.

1) Please fix the following line:

<li><a href="#">Lexus</a></li> <!-- you didn't close the a tag properly -->

2) The mega menu currently has a fixed height, please remove that restriction.

3) Once you have corrected those two things, widen the jsFiddle window and you will see the menu appear as expected.

http://jsfiddle.net/8krqjjj7/8/

Answer №2

The reason the second #sub-nav appears below the first one is because:

#hdr-box nav ul {list-style: none; margin: 0 auto; width: 800px;}

By setting all ul elements to 800px, you are affecting all unordered lists.

It is advisable to use classes for your sub-nav instead of ids, as ids should be unique.

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

Ways to eliminate unnecessary spacing in CSS text-stroke

I am trying to achieve a text-stroke effect with transparent text over an image. However, I am facing an issue where the text-stroke also displays lines within the text itself. I am using the Montserrat font from Google Fonts. Can anyone provide assistance ...

Mouse over the background of an image in jQuery to create a fade-in effect, without affecting any content inside

Currently facing a challenge with jquery. Please take a look at jsfiddle.net/7HXEF/1/. I am trying to create a DIV with a background image that fades in and out when the mouse hovers over it. However, the inner div with a link should not be affected by the ...

Ensuring the input element is correctly aligned in its position

How can I center the input element inside its parent without any top margin? What CSS changes do I need to make? #menu { height:30px; background: #ccc; } #board-name { display:block; margin-left:auto; margin-right:auto; height: 80%; vertical-al ...

How can I eliminate the tiny white square located beneath the scrollbar track?

`::-webkit-scrollbar{ width: 12px; } body::-webkit-scrollbar-track{ background: #f1e9e9; border-radius: 10px; margin-block: 0.1875rem; } ::-webkit-scrollbar-thumb{ background-color: #582965; border-radius: 10px; border: 3px so ...

"Enhance the appearance of bootstrap buttons by applying CSS to add shadow and border when the

Working on a frontend project using the React framework and Bootstrap 5.3 for design. Noticing that shadows are deactivated in Bootstrap by default, which means buttons don't display shadows when active as per the Bootstrap v5.0 documentation. Link ...

Placing a div tag directly beneath another div tag

Imagine you have a div element with the class name divstudent, let's call this one div1. Now, you want to dynamically create another div element below div1, but outside of it using JavaScript. How can you achieve this? "div1" <div class="divstuden ...

Is it possible to create a stylish box for an HTML form?

I'm trying to figure out how to put a form inside a box or have a border around it, but I'm stuck. I want the background to be white and was considering using a transparent option. Are there any experts out there with some simple ideas on how to ...

Troubleshooting Date Problems in Angular

When using the HTML5 date picker, I have encountered an issue where after choosing a date, the ng-model displays an older date instead of the current one selected. <input type="date" ng-model="dateModel" /> For example, when selecting the current d ...

Ways to utilize media queries for repositioning one div on top of another div

Utilizing Bootstrap 5 for website development, my aim is to enhance the responsiveness of the site across various devices. For mobile users, I envision the image-containing div to appear above the div containing the header and paragraph content, but I&apo ...

Utilize AJAX to dynamically refresh the page without having to reload it, enabling the use of both POST and GET methods

In order to avoid reloading the page when refreshing, I am utilizing Ajax for this particular 3-sided content along with JavaScript. Here is the code: Content: <ul id="nav"> <li><a href="ajax_adat.php?id=8&epul=0">Data</a>< ...

The URL requested exceeds the maximum length limit in asp.net, causing a 414 error

I encountered the issue of receiving an "HTTP Error 414. The request URL is too long." While reading through this article, I learned that it is caused by an excessively lengthy query string: Currently in my web.config, I have set maxQueryStringLength to " ...

Select either one checkbox out of two available options

My form includes two checkboxes, allowing users to click on both of them. I'm wondering if it's possible to set it up so that only one checkbox can be selected at a time. For example, clicking on the first checkbox would turn it on while turning ...

placed three blocks inside the table cell

Is there a way to align three blocks in the table-cell layout so that p1 is at the top, p2 is at the bottom, and p3 is in the middle? Here is the corresponding HTML: <div id="table"> <div id="row"> <div id= ...

Tips for centering text on a webpage using the div element in HTML

I need help aligning the text "Monitoring Engineering Dashboard" to the right side of the image in the top-left corner. Currently, it is positioned below the image (Refer to the image below) <div style="width:1200px; margin:0 auto ...

Retrieving Form Validation Error Value in AngularJS

Incorporating AngularJS 1.2 RC2 and utilizing Bootstrap for CSS, I have constructed a straightforward form as shown below: <form class="form-horizontal" name="form" novalidate> <label class="col-lg-2 control-label" for="name">Name</labe ...

Bootstrap grid button with maximum flexibility

I am currently exploring the intricacies of the bootstrap grid system. My goal is to create a set of buttons that look like this: https://i.sstatic.net/V5meG.png Each button should expand to fill the width and height of its container. However, when a b ...

Click on the link within the Checkbox label on MUI

I am working on creating a checkbox for the "Terms of Use," using FormControlLabel to nest a Checkbox. However, I also need to include a link that opens a Dialog component displaying the terms. The challenge is that clicking on the link checks the checkbox ...

Avoid shifting focus to each form control when the tab key is activated

I have a form where users need to be able to delete and add items using the keyboard. Typically, users use the tab key to move focus from one element to another. However, when pressing the tab key in this form, the focus only shifts to textboxes and not t ...

Adding a 'dot' to the progress bar in Bootstrap enhances its visual appeal

I am currently working on a progress bar and I would like it to look similar to this: https://i.sstatic.net/TSDEy.png However, my current output looks like this: https://i.sstatic.net/rQhYc.png I'm puzzled as to why the tooltip is floating there, ...

Looking to dynamically update a date variable based on user selection from a drop-down menu in PHP

I am currently working with a PHP file (index.php) which features a title bar displaying the date in the format (MM YYYY). The dates themselves are extracted from another PHP file named latest_update.php. Within the latest_update file, the dates are specif ...