What could be causing the issue with my HTML drop down menu links not functioning properly

I'm a novice in the world of web design. I recently crafted two drop-down menus for my website, one for projects and the other for labs. While the drop-down functionality itself is operational and the links are clickable, they fail to redirect users to the intended pages. Instead, the user remains on the same page. I am uncertain about what aspect of my HTML is causing this issue. You can view my page at:

<nav class="dropdown">
  <section class="projects">
    <button><h4>Projects</h4></button>
    <ul class="projectlist">

      <li><a href="projects/project2/index.html"><strong>2: Wireframes &amp; Style Tiles</strong> 10 April 2021</a></li>

      <li><a href="projects/project2/index.html"><strong>3: Multi-page Website</strong> 21 May 2021</a></li>
    </ul>
  </section>

  <section class="labs">
    <button><h4>Labs</h4></button>

    <ul class=lablist>
      <li><a href="../index.html.html"><strong>1: Domain Landing Page</strong> 08 March 2021</a></li>
      <li><a href="labs/lab2/index.html"><strong>2: Mt. Washington HTML</strong> 15 March 2021</a></li>
      <li><a href="labs/lab3/index.html"><strong>3: Mt. Washington CSS</strong> 12 April 2021</a></li>
      <li><a href="labs/lab4/index.html"><strong>4: Mt. Washington Table</strong> 17 April 2021</a></li>
      <li><a href="labs/lab5/index.html"><strong>5: Responsive Design</strong> 01 May 2021</a></li>
    </ul>
  </section>
</nav>

Here is the snippet from my CSS:

.projectlist {
    font-family: Montserrat;
    font-weight: 300;
    font-size: 10pt;
    text-transform: uppercase;
}

.lablist {
    font-family: Montserrat;
    font-weight: 300;
    font-size: 10pt;
    text-transform: uppercase
}

.dropdown {
    height: 10vh;
    display: flex;
    justify-content: space-around;
    align-items: center;
    width: 100%;
    margin: auto;
}

.projects, .labs {
    position: relative;
}

/* Additional styling properties omitted for brevity */

Answer №1

The links are semantically correct, but there seems to be an issue stemming from the pointer-events: none style applied to the default state of the link list.

When you click, the focus on your button is lost, causing the overridden values in the CSS rule below to also be lost:

.projects button:focus + ul, .labs button:focus + ul {
    opacity: 1;
    pointer-events: all; // This no longer applies when focus is lost
    transform: translateY(0px);
}

As a result, even though the menu is visible, clicking on a menu item becomes impossible.

You might want to consider toggling the display property of the list element between none and block (or another similar approach).

This alternative approach may cause layout shifts, impacting your Cumulative Layout Shift score for Core Web Vitals.

Another option is to create a dropdown effect by absolutely positioning the list element within a relatively positioned parent. This method avoids layout shifts and still allows you to hide the list using the display property, ensuring that all users, including those who rely on accessibility features, can navigate properly.

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

Achieving a perfect curve with a specific circle radius using CSS

I came across a design tutorial on magic indicators from YouTube and created the following design: https://i.sstatic.net/IJjdCGWk.png However, I am looking to achieve a smoother curve as a continuation of the circle when selected, instead of using element ...

Convert your HTML document into a Microsoft Word file and see the total number of pages in

I have been experimenting with creating a Word document using HTML code. Thanks to various examples, I have made some progress. However, I am facing an issue where I cannot get the total number of pages to display as text on the first page of the document. ...

The "Product URL" in Woocommerce is overlapping with the "Add to Cart" button

Hey, I've encountered a strange issue. I just realized that when I go to my store, the "add to cart" button is overlapping with the product info URL. To better illustrate this problem, please see the images below: https://i.sstatic.net/mkQ8h.png Whe ...

Problems encountered with the navigation on mobile devices

Seeking advice on debugging a non-functioning mobile side menu implementation. The main site, a WordPress site, works perfectly. However, the offsite white label version does not. All HTML has been copied to the white label and necessary CSS and scripts h ...

Maintaining consistent div height in Bootstrap 4 flexbox design

I'm currently using Bootstrap 4 with flexbox enabled, but I'm having trouble making the row > col > div boxes have equal heights. I attempted to use position: absolute, but it's not the ideal solution. Below is a screenshot of the is ...

Is it a scope issue if ng-click is not firing and the function is not working properly?

I'm facing an issue with an animation that is not working as intended. The goal is to have the search button trigger an animation to pull a search bar from the right side, allowing users to input their search query. However, the ng-click function does ...

Do you know the term for when JavaScript is utilized to display specific sections of a png image?

Imagine you have an image file in the format of a PNG which includes various icons intended for use on a website. How can JavaScript be utilized to choose and showcase a specific icon from that image? It's a technique I've observed in practice, b ...

In Bootstrap 3, you can toggle individual collapsible items without affecting others by only closing the specific

I am facing an issue with my Bootstrap collapsible elements. I came across an answer that includes the necessary javascript to close only the collapsible items in my table, while leaving other collapsible items on the page (in the menu) unaffected. These i ...

Using Flask to trigger a Python function that requires input parameters when a button is clicked

I am working on a Flask web application that includes a download button. Instead of triggering a JavaScript function, I want the button to execute a Python method. This Python method should take the recently modified HTML code from the webpage as input. H ...

Tips on aligning text link to the right within li using CSS

I am looking to adjust the position of a text link that is currently aligned to the left inside an li element, by moving it slightly to the right. Is there a way to achieve this effect without changing the overall layout? Page link: CSS: #secondnav li ...

When utilizing bootstrap, encasing an input text element in a label results in the text becoming bold and not occupying the entire width

I have been experimenting with wrapping my text input fields in labels. While this technique works well with pickers on my form, it seems to cause issues when applied to text boxes. If I choose not to wrap the text boxes, the alignment between the label an ...

Z-index creates an obstacle that prevents items from being clicked on

I am facing an issue with my container div that has an inset drop shadow applied to it. Inside this container, I have child elements and I want these children to be clickable. For the drop shadow to show, it is necessary to set the z-index of the child el ...

Update the session's data

Situation : I am working on a basic php form for calculations and pricing. I have set up the add, edit, and delete functions using a switch statement. Within my session, data is stored using $_POST. Issue with Edit Function : if (isset($_POST[&apo ...

Manipulating active classes on different divisions with JQuery

I've completed this code so far: <div class="yearly-archive"> <p> YEAR - <span class="archive-year year-active"> 2014 </span> / <span class="archive-year"> 2013 </span> / <span class="archi ...

Customize PrimeNG component styles

Utilizing the PrimeNG OverlayPanel for a dropdown click feature, I am encountering an issue with moving the default left arrow to the right position. Despite trying various solutions, I have reached a dead end. Would you be able to provide me with some fr ...

Tips for incorporating broadcasting into my Angular application?

console.log('js'); var myApp = angular.module('myApp', ["ngRoute"]); myApp.config(function($routeProvider) { $routeProvider.when('/', { templateUrlnp: 'views/partials/logIn.html', controller: 'LoginC ...

Having trouble reaching the upload file in PHP

I am attempting to transfer files to a remote server using JavaScript, with PHP as the backend. The JavaScript code seems to be functioning properly, but on the PHP side, the $_FILES and $_POST arrays are empty. However, the $_SERVER array contains some da ...

The hideCol method does not work on jqGrid

Encountering a problem with the hidecol method in jqGrid. Despite calling the method, nothing seems to happen. Using version 4.5 of jqGrid. The table is created as follows: // Table creation using jqGrid $('#shipTable').jqGrid({ data: tabl ...

Unexpected behavior: Bootstrap 4 tooltip fails to appear on dynamically-generated elements

The tooltips appearing are not the expected Bootstrap 4 style tooltips. The tooltips currently displayed: https://i.sstatic.net/60Ubm.png compared to the tooltips that should be shown: https://i.sstatic.net/koayu.png I have enabled the tooltips in the ...

Combining inline input fields and select buttons with Bootstrap 3

I've been exploring different ways to align form elements inline, including dropdown buttons and select buttons, but have only had success with smaller size buttons around 40px wide. My main challenge now is trying to create a search bar with an input ...