The primary navigation item is narrower than the submenu item

Here is the issue I am facing:

The sub-menu words on my website are too long and it is affecting the overall design. I need help to make the navigation look better. This is the CSS code I have been using:

/*navigation styles
*/
nav
{
    background: url(../images/bg_footer.png);
}

nav#mainNav ul, nav#mainNav ul li
{
    margin: 0px;
}

nav#mainNav ul li
{
    display: inline;
    float: left;
    position: relative;
}

nav#mainNav ul li a
{
    display: inline-block;
    line-height: 49px;
    padding: 0 14px;
    color: rgb(245,233,227);
    text-transform: uppercase;
    text-decoration: none;
    font-weight: bold;
    letter-spacing: 0.08em;
}

nav#mainNav ul li a:hover
{
    border-bottom: none;
    background: rgb(186,230,78);
    cursor: pointer;
}

/*sub menu*/
nav#mainNav ul ul
{
    position: absolute;
    z-index: 999;
    background: url(../images/bg_footer.png);
    min-width: 100%;
    -webkit-box-shadow: 0px 2px 2px rgba(0, 0, 0, 0.3);
    -moz-box-shadow: 0px 2px 2px rgba(0, 0, 0, 0.3);
    box-shadow: 0px 2px 2px rgba(0, 0, 0, 0.3);
}

nav#mainNav ul ul li
{
    float: none;
    display: list-item;
    font-size: .9em;
    width: 100%;
}

nav#mainNav ul ul li a
{
    display: block;
    line-height: 35px;
    text-transform: none;
}

I've been trying to solve this problem for quite some time now. Any assistance would be greatly appreciated. Thank you!

Answer №1

Do you want the menu "buttons" to be the same width as the drop-down parts?

The issue is that the drop-down ul is absolutely positioned, causing the parent li to not consider its dimensions.

Your current setup looks like this:

<div class="sixteen columns">
    <ul>
        <li>
            <a href="#" style="display:inline-block; position:relative;">Dropdown Menu Header</a>
            <ul style="display:block; position:absolute;">
                <li>Dropdown Item 1</li>
                <li>Dropdown Item 2</li>
                <li>Dropdown Item 3</li>
            </ul>
        </li>
    </ul>
</div>

Consider using a definition list (dl) for the dropdown instead of an unordered list. This way, the menu header is contained within the same element as the menu items. Position the <dd> relatively rather than absolutely and avoid positioning the dt or dd tags at all. This will ensure the menu header and items have the same width, allowing the parent li to adjust accordingly.

Here's how you can structure it:

<div class="sixteen columns">
    <ul>
        <li>
            <dl style="display:block; position:relative;">
                <dt>Dropdown Menu Header</dt>
                <dd>Dropdown Item 1</dd>
                <dd>Dropdown Item 2</dd>
                <dd>Dropdown Item 3</dd>
            </dl>
        </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

Blurring and masking an image within a hollow circle shape

I'm currently working on developing a similar example using react-native-svg. The background image I am using is dynamic and needs a transparent circular mask. Additionally, I want to apply a blur effect to that specific section of the background ima ...

dividing an HTML string into individual variables using JavaScript

How can a string be split in pure JavaScript (without using JQuery/dojo/etc) in the most efficient and straightforward way? For example: var tempString = '<span id="35287845" class="smallIcon" title="time clock" style="color:blue;font-size:14px;" ...

Deliver JavaScript and HTML through an HTTP response using Node.js

My attempts to send both a JavaScript file and an HTML file as responses seem to be failing, as the client is not receiving either. What could be causing the client to not receive the HTML and JavaScript files? I am using Nodejs along with JavaScript and H ...

"Exploring the Power of Jsoup for Selecting

I'm attempting to extract all the links nested within the div class news column index. Here is a snippet of the HTML structure: https://i.stack.imgur.com/zdFWS.jpg Below is the code I have used, but unfortunately, it's not yielding any results. ...

Unable to drag and drop functionality is not functioning properly in Android Emulator with Html and jQuery

As a newcomer to Android, I have successfully created a project in HTML that runs perfectly as intended. However, when trying to run this HTML project on an Android emulator, I encountered an issue with drag and drop functionality not working. I utilized ...

Guide on activating a row with values by clicking an addition button

When using ticket booking apps, we often have the option to add multiple persons. Similarly, I want to provide the user with the ability to add their availability time slot by clicking the "Add New" button to include a second time slot. <div cl ...

Django is causing a TemplateSyntaxError while attempting to extend the "template.html" file with the static keyword

In my template.html file, I have included a lot of boilerplate HTML text. Now, in my index.html file, I have: {% load static %} {% extends static 'template.html' %} Within my settings.py file (relevant parts): INSTALLED_APPS = [ 'notes ...

Explore a Wordpress HTML code

I own a WordPress website using the Photolux theme. My desire is to extract HTML elements such as titles and tags, but for some reason they are not visible. Just to clarify, I am not interested in reading the XML format. If anyone has any suggestions or ...

Row in Internet Explorer 7

I have a function that reveals hidden rows in a table, which works perfectly in all tested browsers except for IE7. The function is written using Prototype.js. function showInactives(){ var row_list = $$('tr.inactive'); var ck =$('inactive_ ...

Do you know the name of the jQuery tool that Mashable employs for showcasing their top 5 images and videos?

Recently, I came across an image scroller on Mashable that caught my eye and I am interested in incorporating it into a new project: I saw it in action on the website, but I am curious about what it actually is. Does anyone know if it is available as a W ...

Create a stylish progress bar using CSS arrows

https://i.sstatic.net/vSPZ3.png I have a progress bar that is almost complete, but the arrow position is not working properly. I have tried using :before to fix it, but the position is still incorrect. <div class="progress-panel"> < ...

The append method is not available for a div element

this is my unique code snippet for (i = 0 ; i< number ; i++){ var iDiv = document.createElement('div'); iDiv.innerHTML = "<label for=\"timeslot\" class=\"p-label-required\">Time Slot</label>" iDiv.i ...

revealing a particular field in jQuery during the validation process

Edit: Currently, I am utilizing the jquery validate plugin and have hidden all error messages initially. Upon checking a specific input field, my objective is to unhide the error message if it is invalid without causing error messages to appear in other f ...

CSS non-adaptive layout

I am looking to maintain consistency in the appearance of my website across all devices, including PCs, iPads, and Galaxy S4s. I am aware of breakpoints, but I am specifically seeking a solution that does not require me to consider them. Is there a strai ...

AJAX Finished Reply

I have successfully implemented a password change function on my website, but I am encountering an issue with displaying a success or fail message. Here is the structure of my HTML code: <form id="change_Pass" action="" method="post"> //stuff ...

I am encountering issues with an HTML table that is in need of fixing, and I must find a solution without relying on

Can someone help me troubleshoot the structure of this table in the given image? It seems like my rowspan and colspan attributes are not working as expected. I've only used CSS to specify the width and height of the cells. https://i.sstatic.net/VtHbH ...

Is there a way to transfer information from an HTML form directly into an Excel file using web services?

Recently, I created an email newsletter using HTML and CSS. This newsletter includes 4 text boxes where users can input their name, family name, phone number, and email address. I am wondering if it is possible to use a web service to transfer this data fr ...

What is preventing me from loading js and css files on my web pages?

I have developed a web application using SpringMVC with Thymeleaf and I am encountering an issue while trying to load javascript and CSS on my HTML5 pages. Here is a snippet from my login.html: <html xmlns="http://www.w3.org/1999/xhtml"> <head&g ...

Jquery scroll animation not reaching the intended position when scrolling upwards

While developing a new feature for my music player, I encountered an issue with centering the track/div upon clicking in the scrollable parent div. Sometimes it doesn't scroll to the center as intended and instead scrolls erratically to the top of the ...

Incorporating invisible surprises into a fixed menu that reveal themselves as you scroll

I am working on implementing a top navigation and a sticky sub-navigation feature. The goal is to have the sticky nav become the top nav when the user scrolls down the page, similar to the functionality on this website - The issue I'm facing is with ...