"Enhancing User Experience with Stylish Drop-down Menu Hover

I'm working on a CSS drop-down menu that has a hover effect, but I'm facing an issue where the a element within the li is not taking up the full width of the li. I want it to utilize the entire width of the li, especially on hover. Does anyone have a solution for this? You can find the Codepen link below: https://codepen.io/darenjm/pen/VWdjWb?editors=1100

<header>
<nav class="clearfix">
<ul>
    <li><a href="#">Home</a></li>
    <li><a href="#">Projects</a></li>
    <li><a href="#">Customers</a>
        <ul>
            <li><a href="#">Our Markets</a></li>
            <li><a href="#">Questionnaire</a></li>
        </ul>
    </li>
    <li><a href="">Employment</a>
        <ul>
            <li><a href="#">Work With Us</a></li>
            <li><a href="#">Open Positions</a></li>
            <li><a href="#">Apply</a></li>
        </ul>
    </li>
    <li><a href="#">Advantage</a></li>
    <li><a href="#">About Us</a>
        <ul>
            <li><a href="#">Colombian Railways History</a></li>
            <li><a href="#">Company History</a></li>
            <li><a href="#">Partners</a></li>
            <li><a href="#">Strategic Partners</a></li>
            <li><a href="#">Videos</a></li>
            <li><a href="#">News</a></li>
            <li><a href="#">FAQ</a></li>
        </ul>
    </li>
    <li><a href="#">Contact</a></li>
</ul>
</nav>
</header>

<div class="box">

</div>




body{
margin:0;
padding:0;
}

header{
background:#001d45;
width:100%;
}

nav{
background:#001d45;
width:85%;
margin:0 auto;
font-family: helvetica;
font-size: 80%;
}
nav ul{
display: flex;
justify-content:space-between;
padding:0;
margin:0;
transition:all .3s ease-in-out;
}
nav ul li{
list-style:none;
flex:1 1 0%;

}
nav ul li > ul{
background:#af2922;
flex-direction: column;

}
nav ul li > ul > li:hover a{
background:#cc534d;
}
nav ul li a{
display:inline-block;
color:#fff;
text-decoration:none;
padding:10px 20px;
}
nav ul li:hover > a{
background:#af2922;
}
nav > ul ul{
position:absolute;
visibility:hidden;
opacity:0;
}
nav ul li:hover > ul{
visibility:visible;
opacity:1;
}

nav > ul > li{
float:left;
}
.clearfix:after{
display:block;
content:"";
clear:both;
}
.box{
background:#d1d3d3;
height:100px;
}

Answer №1

Make sure to apply position:relative; to the parent li element and set width:100% on the dropdown ul.

Check out this example on https://example.com/code-sample

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

The size of the popup does not align properly with the content within it

After creating an extension for Chrome, I specified the dimensions of the popup to be 600 x 300 px. Everything was working perfectly until Chrome updated to version 27. As shown in the screenshot, I set the width and height using CSS, but there is still a ...

Having trouble toggling journal entries in an HTML journal? The Jquery function might not be working properly

I have been tasked with creating a civil war journal for my 8th grade Social Studies class and I decided to present it as an HTML file featuring the title and date of each journal entry. The goal is to allow users to click on each entry to open it while au ...

Efficient ways to enhance CSS animations (including scaling, rotating, and blurring)

In this HTML example, there are two animated pictures - one background and the other an object. Despite using scale and rotate animations, the performance is choppy on full HD monitors, especially in Firefox where it runs at about 20 fps. Initially, jQuer ...

What are some strategies for disregarding global CSS styles?

I am facing an issue on my html page with a specific div structure. The <div id="container">/* lots of nested html with elements like div, ul, li etc */</div> is causing some trouble in my global css file called style.css. The style. ...

Utilizing CSS3 Animation for enhanced hover effects

I have a setup with two divs. One of the divs expands in height when I hover over it. What I'm trying to achieve is to display text with a fade-in effect somewhere on the screen when I hover over that specific div. Additionally, I want to show another ...

Adjustments in margins for printed HTML may vary from page to page in Internet Explorer versions 8 to 11

One challenge I'm facing is with a user-generated report page that is typically printed. There seems to be an unusual bug occurring specifically in Internet Explorer. The layout of the page consists of tables within various divs, all aligned perfectly ...

Creating an HTML table using an array of objects

I'm currently working on creating a function that will generate an HTML table from an array of objects. The array provided below is what I need to convert into a table. let units = [ { 'code': 'COMP2110', &apos ...

The val() function in jQuery returns an empty string when used with a bootstrap popover input field

I'm facing an issue with my bootstrap popup form that includes input fields and a submit button. The problem arises when I try to capture the current value of the input fields using jQuery's val() method after clicking the submit button - it retu ...

I'm looking for tips on how to create a responsive wrapper class within a jumbotron. My experience with this is

I am struggling to make the wrapper class responsive. I have searched everywhere for answers but haven't found a solution yet. Hopefully, I can find some help here: .jumbotron { overflow: hidden; background-color:whitesmoke; opacity:1.0; ...

What is the technique for creating multiple circles using CSS?

Creating multiple circles in CSS and linking them to my HTML file has posed a challenge. The code I have so far is: .circle{ height: 50px; width: 50px; background-color: red; } However, attempting to make another circle using the same 'circle' c ...

Adjusting the positioning of elements in a constantly changing scenario

Utilizing Bootstrap, I aim to keep the top-right corner of the red background fixed to the upper right corner of the blue section within the visible area regardless of window resizing due to its responsive design. The red element should be position fixed ...

No reaction being triggered by the CSS Media Query

I'm attempting to have the title-image stay static when the screen size is below 1052px so that it fills the full width of the viewport, but the styles should only be applied when the screen size is less than 992px. This is from the Web Development co ...

Is there a way to switch out the WordPress page title for an image instead?

I am trying to change up the appearance of my WordPress site by replacing the text on page titles with images. Working on a child theme locally, I need to customize each page individually as they will have different images. The current state is as follows ...

Incorporating CSS style to individual rows in an HTML table

Is there a way to determine if a specific string, such as 'LA DEFENSE', is present in my HTML table and then change the background color of that line to red? https://i.sstatic.net/Yq7qF.png This is what I am looking for: $("#colorline").click( ...

Tips on applying a class to a host element using @hostbinding in Angular 2

I've been wanting to assign a class to the host element of my component, and initially I used the host property in this manner: @Component({ selector: 'left-bar', host: { 'class': 'left-bar' }, templateUrl: 'a ...

Tips for looping through an HTML document using Python to extract information from Wikipedia

I am working on developing a tool to extract data from the Wikipedia API. Within an XML file named wikiepedia.html, I have several links that I want to parse through line by line in order to retrieve information which can then be formatted into JSON. The ...

Error 404 encountered while attempting to access dist/js/login in Node.JS bootstrap

I currently have a web application running on my local machine. Within an HTML file, I am referencing a script src as /node_modules/bootstrap/dist/js/bootstrap.js. I have configured a route in my Routes.js file to handle this request and serve the appropri ...

Can $refs cause issues with interpolation?

I'm currently learning Vue.js and the course instructor mentioned that modifying the DOM element using $refs should not affect interpolation. In fact, any changes made directly to the DOM will be overridden by interpolation if it exists. However, in m ...

Why isn't my HTML reflecting the CSS changes I've made?

My CSS code is not applying to the HTML in general, only to h1 and h3. I have used similar looking code before and it worked fine. html { text-align:center; border:25px dotted #ff5c33; background-color:#00b300; color:#ff5c33; font-fami ...

Using JavaScript to add a class when hovering over an element

I am trying to customize the ul inside one of my li elements in the nav by adding a class when hovered. However, I am encountering an issue where the menu disappears when I try to click on it after hovering over it. I want to achieve this functionality usi ...