Unable to access elements located underneath the div

I'm working on creating a simple menu using CSS and jQuery. Everything seems to be functioning correctly, but I've noticed that when I open the menu, I am unable to click on any elements below it.

Check out the menu here

<header> 
<nav>
    <span>
        <img src="img/header.png" alt="logo">
        <i class="fas fa-bars trigger">menu</i>
    </span>
    <span class="menu-container hidden">
        <div class="menu">
            <a href="#">option</a>
            <a href="#">option</a>
            <a href="#">option</a>
            <a href="#">option</a>
        </div>
    </span>
</nav>

<p><a href="#">Option I'm struggling to click</a></p>
<p><a href="#">Option I can't seem to click</a></p>
<p><a href="#">Option that won't click for me</a></p>
<p><a href="#">Unable to click this option</a></p>

The jQuery code is just toggling a class to move between the positions of the div

const menu = document.querySelector('.menu');
const trigger = document.querySelector('.trigger');

function toggle() {
  menu.classList.toggle('menu--open');
}

trigger.addEventListener('click', toggle);

Here's a snippet of my CSS. The animation is purely CSS-based, and I am shifting the div's position when the menu button is clicked.

.menu {
  position: relative;
  top: -300px;
  transition: 0.3s all;
}

.menu--open {
  top: 0;
  transition: 0.3s all;
}

nav {
    width: 100%;
    height: 70px;
    position: absolute;
    z-index: 1;
    top: 0;
}

nav span {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

nav span:nth-child(1) {
    background: white;
    z-index: 1;
    position: relative;
}

.menu-container {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.fa-bars {
    margin-right: 20px;
    font-size: 20px;
}

.fa-bars:hover {
    cursor: pointer;
}

span .menu {
    background: #95baa8;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
}

span .menu a {
    padding: 15px;
    text-decoration: none;
    color: white;
}

Answer №1

The header is currently overlapping the links, obscuring them from being clicked. You have the option to utilize the CSS attribute pointer-events: none to resolve this issue. Additional information can be found in this response.

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

Several target elements on a single page

I am currently facing a problem with maintaining the active state of one anchor tag's target while clicking another button within the main identifier. Upon clicking the INTEL button, its opacity changes from 0 to 1. However, upon clicking Data Histor ...

Using JQuery to target the input value based on its ID

When trying to extract the value of the input with id "registration_type," I entered the following command in the console: $('#registration_type') The output displayed was: <input id=​"registration_type" name=​"contact_registration[ty ...

An alternative method for storing data in HTML that is more effective than using hidden fields

I'm trying to figure out if there's a more efficient method for storing data within HTML content. Currently, I have some values stored in my HTML file using hidden fields that are generated by code behind. HTML: <input type="hidden" id="hid1 ...

How can I enhance content sharing by including both text and links in my emails and social media posts using React and react-share?

Is there a way to share a link on email, Facebook, Twitter, etc. using react-share? I tried using an a tag but it didn't work. Any suggestions or ideas would be greatly appreciated. Thank you! <EmailShareButton url="www.example.com" subjec ...

The bootstrap card layout breaks with Google Maps in Chrome and is not functioning properly

I have encountered an issue with the bootstrap card layout and Google Maps integration. When I move the Google Map to a card in a right column, it does not display properly. However, placing it in the first column works perfectly fine. This problem seems t ...

I'm attempting to align my text at the center of my tab navigation but it doesn't seem to be working

I'm struggling with centering the text within the li tags in my tabbed navigation bar. I don't want to add padding to the top of the text because I want the entire tab to be clickable. Any advice on how to achieve this? Also, how can I make the l ...

What steps should I follow to set up HAProxy for server sent events compatibility?

I am currently working on integrating Server Sent Events into an established application. The challenge I face is that there may be extended periods (approximately 5 minutes) where no event is generated. I would like to set up the endpoint in a way that it ...

How can I retrieve the $index value of an ng-repeat element within a uib-dropdown?

I am currently working on implementing an ng-repeat loop that includes a dropdown menu for each element. I want the dropdown menu to contain functions that operate on the specific element, requiring access to the index of that element. Below is the code sn ...

ridiculing callback within parameter

I have a model setup in the following way: export class MyClass { grpcClient: MyGRPCClient; constructor(config: MyGRPCClientConfig) { this.grpcClient = new MyGRPCClient( config.serverUrl, grpc.credentials.createInsecure(), ); ...

I'm looking to integrate Jest in my React project with npm. How can I achieve

I've developed my application with create react app and npm. While reviewing the official documentation for jest at https://jestjs.io/docs/tutorial-react, I noticed that they only provide information on testing CRA apps using yarn. Does this suggest t ...

Connect-busboy: The file being piped to the write stream is either empty or incorrect, depending on its type

My current project involves testing a file upload feature using connect-busboy. Interestingly, I have encountered a peculiar issue when uploading PNG files - although the file gets uploaded, the content seems to be incorrect and unable to open. Upon furthe ...

What is the best way to style a tooltip in an ASP.NET application using CSS?

protected void grd_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { foreach (TableCell cell in e.Row.Cells) { ...

Using ngRepeat to Minimize TH-Tags in AngularJS

Here is the current section of TH-Tags in the view: ... <th> <a href="" ng-click="sortReverse = !sortReverse; order('fname',sortReverse)"> Firstname <span ng-show="sortType=='fname' && ...

Increase the options available in the dropdown menu by adding more selected items, without removing any already selected

I came across this code on the internet http://jsfiddle.net/bvotcode/owhq5jat/ When I select a new item, the old item is replaced by the new item. How can I add more items without replacing them when I click "dropdown list"? Thank you <select id=&qu ...

Manipulating DropDownList Attributes in ASP.NET using JavaScript

I am facing an issue with populating a Dropdownlist control on my ASCX page. <asp:DropDownList ID="demoddl" runat="server" onchange="apply(this.options[this.selectedIndex].value,event)" onclick="borderColorChange(this.id, 'Click')" onblur="bo ...

Tips for resolving a double click issue with a jQuery slide up/down animation

When I click a button, there is an animation that makes a div slide up and then down again. It functions the way I want it to, but the first time you click it, it doesn't work; you have to click twice for it to respond. Someone recommended using... ...

Unable to invoke the setState function within the onSubmit handler of Formik

Every time I submit my form, I want to display an alert. I attempted to pass my state as a prop to the component, but it didn't work. Here's how my class state looks: this.state = { alert_variant: '', alert_heading: ...

Error encountered when attempting to generate a hyperlink

Whenever I try to assign hyperlinks to each image name, I keep encountering an undefined imgitem error in the hyperlink(s). Could it be that I am incorrectly placing the <a> tags? echo '<td width="11%" class="imagetd">'; if (empty($a ...

Remove httpOnly cookies in Express

Can browser cookies with the attribute HttpOnly:true be deleted? Here is a snippet of my login endpoint: async login(@Ip() ipAddress, @Request() req, @Res() res: Response) { const auth = await this.basicAuthService.login(req.user, ipAddress); ...

retrieve all users who are not currently in the group

I'm currently struggling to retrieve all users who are not members of a particular group within a many-to-many association. After investing several hours into researching and experimenting, I've developed the following code. However, it falls sh ...