The Navbar Items Background Color is not functioning as anticipated

When the hamburger is clicked on mobile devices, I want my navbar items to have a full background-color display that only shows the logo, the hamburger icon, and the navigation items. The main content of the landing page should be hidden unless the hamburger menu is closed.
1 Here is an image of what I am trying to achieve on mobile: https://i.sstatic.net/18wM9.jpg

  1. This is how it currently looks: [![

Below is the code for my Navbar.js:

import React, { useState } from "react";
import { FiMenu, FiX } from "react-icons/fi";
import { Link } from "react-router-dom";

export default function Navbar() {
    const [open, setOpen] = useState(false);

    const handleClick = () => {
        setOpen(!open);
    };

    const closeMenu = () => {
        setOpen(false);
    };
  return (
    <div className="navigation">
      <nav className="navbar">
        <Link to="/" className="nav-logo" >
        ESEOWIE{" "}
        </Link>
        <div onClick={handleClick} className="nav-icon">
                {open ? <FiX /> : <FiMenu />}
            </div>
        <ul className={open ? "nav-links active" : "nav-links"}>
          {/* <li className="nav-item">
            <Link to="/" className="nav-link" onClick={closeMenu}>
              Homepage
            </Link>
          </li> */}
          <li className="nav-item">
            <Link
              to="/career"
              className="nav-link" onClick={closeMenu}
            >
            Political Career
            </Link>
          </li>
          <li className="nav-item">
            <Link
              to="/career"
              className="nav-link" onClick={closeMenu}
            >
            Professional Career
            </Link>
          </li>
          <li className="nav-item">
            <Link
              to="/academics"
              className="nav-link" onClick={closeMenu}
            >
              Academics Pedigree
            </Link>
          </li>

          <li className="nav-item">
            <Link
              to="/social"
              className="nav-link" onClick={closeMenu}
            >
             Social Enterprise
            </Link>
          </li>
          <li className="nav-item">
            <Link
              to="/publications"
              className="nav-link" onClick={closeMenu}
            >
             Publications
            </Link>
          </li>
          <li className="nav-item">
            <Link
              to="/contact"
              className="nav-link" onClick={closeMenu}
            >
              Contact
            </Link>
          </li>
        </ul>
      </nav>
    </div>
  );
}

[2] [2]

Here is the CSS code for my Navbar styling:

.navbar {
    height: 80px;
    width: 100%;
    /* background: blue; */
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 2rem;
    font-size: 1.2rem;
}

.nav-logo {
    text-decoration: none;
    color: white;
    width: 101.23px;
    height: 9.67px;
    font-family: Calibre;
}

.nav-links {
    display: grid;
    grid-template-columns: repeat(6, auto);
    grid-gap: 20px;
    list-style: none;
}

.nav-link {
    text-decoration: none;
    color: white;
    transition: 0.3s all;
}

.nav-link:hover {
    color: red;
}

.nav-icon {
    display: none;
    font-size: 2rem;
    cursor: pointer;
}

@media only screen and (max-width: 500px) {
    .navbar {
        position: relative;
    }

    .nav-links {
        display: flex;
        flex-direction: column;
        position: absolute;
        top: 180px;
        left: -100%;
        transition: 0.5s all;
    }

    .nav-links.active {
        background: #4D0ADB;
        left: 51px;
    }

    .nav-item {
        padding: 10px 0;
    }
    
    .nav-icon {
        display: flex;
    }
}

Answer №1

Check out this solution

.navigation {
height: 100vh; 
z-index: 5 // make sure this value is higher than the landing page content's z-index
}

Don't forget to assign a lower z-index to the landing page content

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

Animating the Three.js Globe camera when a button is clicked

Struggling to create smooth camera movement between two points, trying to implement the function below. Currently working with the Globe from Chrome Experiments. function changeCountry(lat, lng) { var phi = (90 - lat) * Math.PI / 180; var theta = ...

Pros and Cons of Using HTML5 Mode versus Hash Mode in AngularJS

When using AngularJS 1.3, it is necessary to include the <base> tag in HTML5 mode. This led me to consider the pros and cons of HTML5 mode versus Hash mode. In Hash mode, the major drawback is that URLs can appear unattractive and may not be easy fo ...

Is it possible to incorporate spread syntax(...) within a vue.js 2.x template?

Is it possible to utilize a similar structure in a vue.js template? <template> <vxe-table> <vxe-column v-for="options in someConsts" ...options width="160"> </vxe-column> </vxe-ta ...

Display or conceal toggle in ruby utilizing jQuery

I'm facing an issue with the functionality of a button that is meant to hide and show a form using jQuery. Initially, I added a path to signup in the button so that it would display and function properly. Now, when I click the button, the form shows u ...

Error with top-level-await when integrating Firebase with Stripe Checkout session

I have been working on setting up a checkout session using the stripe firebase extension, but I encountered an error: ./pages/viewer.js Module parse failed: The top-level-await experiment is not enabled (set experiments.topLevelAwait: true to enable it) F ...

What is the method for adding pages to the ion-nav component in Ionic with Angular?

How can I implement a UINavigationController-like functionality in iOS using an ion-nav element? The example provided here is in Javascript, but I need assistance with implementing it in Angular. Specifically, I'm unsure of how to programmatically add ...

Activate the service function within the identical service

Currently, I am facing an issue while trying to call a function within the same AngularJS service. In my controller, I am able to successfully call the 'geocoding' function without any problems. However, within the 'geocoding' functio ...

Encountering a ReferenceError stating that the window object is not defined while building a React Leaflet application

In my upcoming nextjs project, I've incorporated react-leaflet. It behaves flawlessly in dev mode. However, upon attempting to build the project, it throws a ReferenceError: window is not defined. Despite setting ssr to false in dynamic, the error per ...

Toggling the switch leads to a BadRequestKeyError: 400 Bad Request

I am working on a project with Python and Flask to create an index.html that displays a list. My goal is to implement a filter for this list using a Bootstrap switch. Currently, my code successfully displays the index.html list via a GET request. The switc ...

What is the best way to access the text content of a nested HTML element for automation tasks with Selenium or Protractor?

Can anyone help me with this HTML code snippet? I want to extract and display only the text within the desc class - "Print this", ignoring the text in the spell class. This needs to be done using either Protractor or Selenium. <span class="desc"> Pr ...

After using driver.execute_script, the variable results in nil

Attempting to retrieve a lengthy string of URLs separated by commas is proving challenging. The code functions correctly in the console, but when running the script, the ruby variable urls_list remains nil. require 'rubygems' require 'selen ...

What could be the reason my node.js application built with express is unable to retrieve data from mongoose

Currently, I have experience in PHP MVC and recently delved into learning Nodejs. Here is how my app directory structure looks like: root - controllers -user.js - model -user.js - public -stylesh ...

Issues with the navigator.contacts.find function occurring when using cordova or phonegap

I am attempting to retrieve the contacts stored on a mobile device. The code snippet I am using is not functioning as expected - specifically, the navigator.contacts.find method isn't producing any outcomes. There are no error messages or success conf ...

Exploring the power of Angular by implementing nested ng-repeat functionalities:

I am currently working on an ng-repeat feature to add items from the array (album array). Everything seems to be functioning correctly. However, I also have a colors array that should assign different background-colors to the card elements of the album arr ...

Is there a way to make text within a Div selectable even if it is positioned behind another Div with a higher z-index?

Currently grappling with some code, unfortunately cannot easily paste the problematic part here as I am unsure of its exact location. Here's the situation: there is a div containing text that needs to be selectable, however, there is another div with ...

Exploring alternatives to setTimeOut() for precise timing of Javascript events, especially when incorporating third party events

Here is the HTML element stack that I am working with: <div class="btn-group btnSortAssType" data-toggle="buttons"> <label class="btn ink-reaction btn-primary active"> <input type="checkbox" value="m">Model </label> ...

Error encountered while trying to display the react-bootstrap table

I am having trouble rendering sample data using react-bootstrap tables. Every time I try, I encounter the error: TypeError: Cannot read property 'filter' of undefined I've searched on various platforms and visited multiple links, but I ca ...

What steps can be taken to resolve the problem of CSS sprite causing blurry images on mobile devices when using background-position?

In the world of CSS, working with regular images is usually straightforward - setting the width to 50px will display them perfectly on both desktop and mobile devices without any issues as long as the image quality is good. However, when it comes to using ...

Recreating dropdown menus using jQuery Clone

Hey there, I'm facing a situation with a dropdown list. When I choose "cat1" option, it should display sub cat 1 options. However, if I add another category, it should only show cat1 options without the sub cat options. The issue is that both cat 1 a ...

Optimal method for displaying content in Vue.js in read-only mode

I am currently working on a code snippet used to display messages exchanged between two users. <template> <main> <form action="" method="post" @submit.prevent="sendMessage"> <textarea name="message" id="messag ...