What is the best way to ensure that my drop-down menu items match the size of the parent nav bar?

I'm having trouble creating a dropdown menu using only CSS. Specifically, I am struggling to ensure that the dropdown menu is the same size (width and height) as its parent element.

Here is a link to a working example: HERE

This is the snippet of HTML containing the <nav> section:

<nav>
    <ul>
        <li><a href="#">Home</a></li>
        <li><a href="#">Menu With Menus</a>
            <ul>
                <li><a href="#">opt 1</a></li>
                <li><a href="#">opt 2</a></li>
                <li><a href="#">opt 3</a></li>
            </ul>
        </li>
        <li><a href="#">Whatnot</a></li>                
    </ul>
</nav>

Here is the corresponding CSS:

nav ul {
    position: relative;
    display: inline-table;
    list-style: none;
}

nav ul li {
    float:left;
    list-style-type: none;
}

nav ul li a {
    background-color: #dae8ec;
    color: rgb(233,78,31);
    display: block; 
    font-weight: bold; 
    margin: 0 auto;         
    padding: 9px 18px 9px; 
    text-decoration: none;
    border: 1px solid black;
    border-radius: 2px; 
}

nav ul ul {
    display: none;
    position: absolute; 
    top: 100%;
}

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

nav ul ul li {
    float: none;
    position: relative;
}

nav ul ul li a {
    padding: 7px 30px;
    color: rgb(233,78,31);
}

nav ul li a:hover {
    background: rgb(138, 92, 132);
    color:#dae8ec;
}

If you have any suggestions or tips on how to achieve equal sizing for the dropdown menu, it would be greatly appreciated. Thank you!

Answer №1

Check out my JS Fiddle Demo

<nav>
    <ul>
        <li><a href="#">Home</a></li>
        <li><a href="#">Menu Withs</a>
            <ul>
                <li><a href="#">opt 1</a></li>
                <li><a href="#">opt 2</a></li>
                <li><a href="#">opt 3</a></li>
            </ul>
        </li>
        <li><a href="#">Whatnot</a></li>                
    </ul>
</nav>

Cheers to a successful project!!

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

Adjust the height of the div container and implement a vertical scroll feature on the fixed element

I created a fiddle and was hoping to enable scrolling, but I have been unable to find a solution. http://jsfiddle.net/sq181h3h/3/ I tried both of these options, but nothing seems to be working: #league_chat { overflow-y:scroll; } #league_chat { ...

Positioning parent and child elements using CSS

If you have a moment, please check out this URL where I've provided a more detailed explanation of the issue: How to Make an Image Responsive Within a Division I am looking to adjust the width of .slider-wrapper to 100%. Can anyone advise on how to u ...

What is the proper method for delivering Javascript code with rendered HTTP to a client?

During the development process, I made a decision to switch to server-side rendering in order to have better control and take advantage of other benefits. My web application relies heavily on AJAX with no url redirecting, creating a website that dynamicall ...

Unable to view image stored as a blob

https://i.stack.imgur.com/8v90u.pngI have been studying these examples PHP display image BLOB from MySQL How to display an BLOB image stored in MySql database? They all demonstrate the same method of displaying images saved as blob. In my case, I ha ...

Ways to identify an element within a webpage

I'm currently working on creating a chrome extension that can detect the presence of specific elements on a webpage. The goal is to have this extension automatically run every time a new page is opened and display a popup message if the element is fou ...

Detecting file corruption from a form-based web page file upload (using input type="file")

Can file corruption occur during the process of uploading a file through a web form? Specifically, when an input of type "file" is included in a form submission and the file is saved on the server (typically in a designated temporary upload directory). Is ...

Determine if the HTML Application Cache is void

Our website uses a "manifest.appcache" file to manage the application cache. Some pages are designed to be accessed offline, so they have references in the html tag to the manifest, while others do not. Is there a way to determine if the cache is empty ac ...

Limit the selected values to calculate a partial sum

Imagine two distinct classes called professor and student: professor.ts export class Professor { id: number name: string } student.ts import { Professor } from "./professor" export class Student { ...

CSS prefers to remain within its original controller and does not want to be uploaded from any other source

My webpage includes headers and footers with CSS in them. Strangely, when I load the view using one controller, the CSS displays correctly. But when I try to load the same view using a different controller, the CSS doesn't appear at all. What could b ...

Comparing the efficiency of Jquery draggable with thousands of elements versus updating the elements continuously

Currently, I am developing an application that involves dragging an image using Jquery's draggable utility. The image is accompanied by several overlay divs containing various components positioned based on pixel locations, sometimes reaching into the ...

What is the best way to transfer Javascript variables from an HTML template to a view function in Django?

Currently, I am developing a website using Django. One of the features I'm working on is a form in my HTML page that includes a textbox for users to input their name with a label "Enter your name". Underneath the textbox, there is a submit button. ...

Incorporate a JSON file into the Webpack output separately from the bundle.js file

Is there a way for my webpack application to read a JSON file at runtime without including it in the bundle.js after packaging? I want the JSON file to be available in the package folder but not bundled with the rest of the code. How can I achieve this? ...

Tips for securely transmitting data via a hidden form using the POST method

I have a query that displays records of people, and I want to send the id_Persona using a hidden form through a post function to the idsPersonas.php page. However, when I try to do this, it redirects me to an undefined page. Here is the code snippet: < ...

Ensure this div adapts to different screen sizes

I have attempted using a width of 100%, but unfortunately, it did not result in a responsive design. To illustrate my point, here is the link to what I am striving to achieve in terms of responsiveness: codepen link div { background:url(https://i.stac ...

Is there a way to update CSS dynamically in server-side ASP.NET?

Is there a way to dynamically change the CSS values based on the server's response? I attempted to use inline expressions, but unfortunately, it did not yield the desired outcome. @keyframes loading-1 { 0% { -webkit-transform: rotate(<%=cpuRigh ...

What are the best practices for utilizing intro.js effectively on mobile devices?

Description When using introjs on mobile devices with a screen width of less than 600px, the tooltip ends up covering the element. When I hold the device horizontally, the tooltip adjusts its position accordingly. I attempted to apply custom CSS to the too ...

Is there a way to use Javascript to launch a new page on my website?

I'll do my best to provide a clear explanation of what I need. Take a look at this: My website is filled with a plethora of news articles, all retrieved from the MySQL database using select * from table_name. Displaying so much news on one page can ...

Exploring how to set dropdown menu width for Angular2 mat-select options

Currently, I am using the angular2 mat-select control and facing an issue with the width and position of its dropdown list menu. By default, it is wider and overflows the element on both sides by a few pixels. I have not found any option for adjusting the ...

Steps for choosing an image and embedding it within a div element

Upon loading the site, an image is displayed with the following code: <img id="some_Image" src="some_source"> However, I am looking to avoid requesting this image again from "some_source". This is because calculating the image can be resource-inten ...

Having trouble with the DataTables jQuery plugin? Seeing a blank page instead of the expected results?

I've been trying to set up the Datatables jquery plugin for my HTML table but it's not working as expected. I have linked to the Datatables CDN for CSS styling and script, along with Google's hosted jQuery plugin. Additionally, I have a loca ...