Issues with the Dropdown Menu

I'm currently working on a dropdown menu and I've encountered two issues.

  1. When I hover over the links in the main navigation bar (such as 'about' and 'connect'), only the actual words are clickable, not the entire area that the text occupies like with 'works' and 'achievements.'

  2. In the dropdown menu itself, when I hover over the links, the entire section of text is not being highlighted.

I've attempted to resolve this by adjusting padding and margins but it hasn't completely fixed the problem.

This is the CSS code I'm using:

/*CSS CODE HERE*/ <br/>

And here's my HTML markup:

/*HTML CODE HERE*/ 

You can view my code preview via this link: https://jsfiddle.net/zinctan/83jh28o4/1/.

Answer №1

Here are the main causes of the issues:

  1. The padding should be added to the link itself, not the li element.
  2. Similarly to the previous issue, you also need to include width:100% in the links for them to occupy the full width.

Additionally, there is another problem: You forgot to insert <a> elements for the li's that contain dropdowns. These links should be included like the others.

Check out the DEMO

Answer №2

Make sure to add padding to the links:

#nav ul li a {
  display: block;
  padding: 7px 10px;
}

Additionally, the <li> elements on the same level must have an <a> tag for it to function properly, like so:

<a href="#" class="navText">WORKS</a>

In this section of the code, adjust the width to 140px (subtracting 10px of padding on each side from the total 160 pixels):

#nav ul li ul li a:hover {
    width: 140px;
}

Visit this link for more information.

Answer №3

body {
background-color: #FFFFF5;
font-family: Gotham, "Helvetica Neue", Helvetica, Arial, sans-serif;
}
#nav {
width: 480px;
float: right;
height: 30px;
border-top: thin solid #000000;
line-height: 0px;
text-align: right;
padding-right: 20px;
}
.navText {
color: #000000;
text-decoration: none;
font-family: Gotham, "Helvetica Neue", Helvetica, Arial, sans-serif;
font-size: 17px;
}
#nav ul {
text-align: left;
display: inline;
list-style: none;
padding-top: 0px;
padding-right: 0px;
padding-bottom: 0px;
padding-left: 0px;
}
#nav ul li {
font: 17px/17px sans-serif;
font-family: Gotham, "Helvetica Neue", Helvetica, Arial, sans-serif;
display: inline-block;
position: relative;
cursor: pointer;
padding-top: 7px;
padding-bottom: 7px;
padding-left: 10px;
padding-right: 10px;
}
#nav ul li a:hover {
background: #555;
color: #fffff5;
display: inline-block;
position: relative;
cursor: pointer;
}
#nav ul li:hover {
background: #555;
color: #fffff5;
}
#nav ul li ul {
position: absolute;
top: 30px;
left: 0px;
opacity: 0;
visibility: hidden;
-webkit-transiton: opacity 0.2s;
-moz-transition: opacity 0.2s;
-ms-transition: opacity 0.2s;
-o-transition: opacity 0.2s;
-transition: opacity 0.2s;
width: 160px;
}
#nav ul li:hover ul {
display: block;
opacity: 1;
visibility: visible;
}
#nav ul li ul li {
background: #555;
display: block; 
color: #fffff5;
font: 13px sans-serif;
font-family: Gotham, "Helvetica Neue", Helvetica, Arial, sans-serif;
}
#nav ul li ul li a {
text-decoration: none;
background: #555; 
display: block; 
color: #fffff5;
font: 13px sans-serif;
font-family: Gotham, "Helvetica Neue", Helvetica, Arial, sans-serif;
}
 #nav ul li ul li:hover {
background: #666;
}
#nav ul li ul li:hover a {
    background: #666;
}
</style>
     <div id="nav">
      <ul>
        <a href="about.html" class="navText"><li>ABOUT</li></a>
        <li>WORKS
        <ul>
      <li><a href="written.html">Written</a></li>
      <li><a href="photos.html">Photography</a></li>
         <li><a href="film.html">Film</a></li>
         <li><a href="other.html">Other</a></li>
  </ul>
    </li>
        <li>ACHIEVEMENTS
        <ul>
      <li><a href="skills.html">Skills</a></li>
         <li><a href="acad.html">Academic</a></li>
         <li><a href="cca.html">Co-Curricular</a></li>
  </ul>
        </li>
        <a href="connect.html" class="navText"><li>CONNECT</li></a>
      </ul>
    </div>

1: Modify the location of anchor tags with list items:

<a href="about.html" class="navText"><li>ABOUT</li></a>
…
<a href="connect.html" class="navText"><li>CONNECT</li></a>

2: Update the CSS rule for hovering on nested unordered list items:

CSS

#nav ul li ul li:hover {
  background: #666;
}

Also, append the following style rule:

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

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

css subcategories - divs failing to meet css criteria

I am encountering an issue where my subclass is not working on DIV elements. While the CSS rules are able to match inline tags like span and a, they do not seem to work with div. Please refer to the example provided below: <style> .row { disp ...

Concerns with combining key value pairs in Typescript Enums

Could you help me figure out how to properly implement an enum in my drop-down so that I can only display one value at a time? Currently, I am seeing both the key and the value in the list. This is my enum: export enum VMRole { "Kubemaster" = 0, "Kub ...

Shifting text upwards within a document

I'm struggling with CSS and bootstrap as I have limited knowledge in this area. I have multiple divs on a page that I want to align based on our old website design. The problem I'm facing is that one div is larger on the right, causing a lot of ...

Certain browsers have difficulty running CSS keyframes animations

As I work on my website, I have integrated a CSS keyframes animation that is triggered by clicking a link connected to a JavaScript function. Here is an excerpt from my CSS file: #banner { background-color: #00BBD2; position: absolute; width: 100%; heigh ...

Switch the text display by clicking on a different button in the list

I am currently dealing with an issue involving a list of boxes containing text/images and buttons for expanding/collapsing the text. Whenever I click on another item's button, the text box that was previously opened gets closed, but the button text re ...

Resetting the countdown timer is triggered when moving to a new page

In my current project, I am developing a basic battle game in which two players choose their characters and engage in combat. The battles are structured into turns, with each new turn initiating on a fresh page and featuring a timer that counts down from ...

Troubleshooting: Why isn't my jQuery Click Event functioning in Mozilla but working perfectly fine in

While I know this question has been asked before, I can't seem to locate the posts I remember reading about it. I apologize for any duplication, but I am trying to implement a "click anywhere BUT here to close element overlay" effect on my personal we ...

Adjust the max-height to occupy the entire available space

One of the challenges I'm facing with my web application is designing the layout in a way that all elements interact seamlessly. The structure is as follows: <body> <nav> <-- top navigation bar <ol> <-- breadc ...

Incorporating outside content into HTML

Currently, I am working on a project at my job which requires me to create a comprehensive help file with multiple chapters and extensive text all within one large HTML file. However, as the text will need to be translated into different languages, I am lo ...

Ensure that PHP form validations are checked when submitting the form using jQuery

I have created a form in HTML with basic verification. Here is the code: <form class="" action="submit/save" method="POST" enctype="multipart/form-data" id="submit_form"> <input class="form- ...

Tips for concealing the final click (add) tab after it has been clicked and revealing the hidden (add) button when the user clicks on the remove button

I have created a form where users can add tests. Everything is working smoothly but I want the previous "Add Another Test" field to be removed when the user clicks on it and a new field to be shown. Everything is running well, but the issue is that when t ...

Creating a List Item with Equal Height as Its Parent Container

<nav> <ul id="navUl"> <li> <div class="settingsDiv"> hey </div> </li> </ul> </nav> I am trying to adjust the height of the div element to match the height of the nav. My g ...

The art of fluidly positioning elements in Bootstrap columns

My goal is to showcase objects in 3 columns using Bootstrap 4. However, when I implement the code provided, the objects are only displayed in a single column, as shown here: example of 1 column layout. What I actually want is for the objects to be arrange ...

More content will not be displayed beneath folded DIVs arranged to stack on mobile devices

On my website, I have two separate sections dedicated to use cases and benefits. Here is the code: .onboardmessaging { min-width: 100%; } .onboardmessagingwrap { min-width: 100%; } .usecase { padding-left: 8vw; max-widt ...

Angular routing template failing to execute inline JavaScript code

I'm facing an issue with my Angular.js routing implementation. I have successfully displayed the HTML code in templates using angular.js, but now I am encountering a problem with my template structure: <div id="map_canvas" style="width:95%; heigh ...

The function was expecting an array for ordering, but instead received an object

I need help filtering my results based on their position. Whenever I try to use the orderBy function, it breaks the page because the result is not an array. How can I fix this issue? I'm currently stuck at this point. This is how I attempt to filter ...

Why is it that @font-face fails to function properly even after being defined correctly?

Here's the @font-face code I've been using: @font-face { font-family: "NotesEsa-Bold"; src: url("C:\Users\test\Desktop\Webpage\Fonts\NotesEsaBol.ttf") format("truetype"); /* Safari, Android, iOS */ font-we ...

Simulating the behavior of display blocks

HTML similar to the example below is working perfectly, however, there seems to be an issue with Sharepoint 2013's editor. When trying to edit the link text within a block that has 'display: block' or 'float', it becomes impossible ...

The issue I am experiencing within my PHP code is that the redirection to the gratitude page is not functioning correctly when utilizing

As a newcomer to PHP, I have been struggling with an example code from a website that is not redirecting to the thank you page as expected. Moreover, the email functionality is not working properly either. The code was sourced from: Upon downloading the f ...

Send the user to a specified destination

Currently, I am working on creating a form that allows users to input a location and have the page redirect to that location after submission. However, I am facing difficulty in determining how to set the value for action="" when I do not know what the loc ...