The sliding hamburger menu children fail to move in unison with the parent

I'm currently working on a dynamic sliding navigation menu that activates when the hamburger icon is clicked. However, I am facing an issue where the child <a> elements are not sliding along with the parent div.

You can see how it currently looks by checking out these images: Menu open view and Menu closed view.

The two <a> elements remain stationary and do not transition with the rest of the content.

This is the CSS code snippet:

.wrapper {
    position: absolute;
    z-index: 100;
    top: 0;
    left: 0;
    height: 100%;
    width: 0%;
    pointer-events: none;
    transition: 0.5s;
}

.wrapper > .BurgerMenu {
    display: block;
    top: 0;
    left: 0;
    height: 100%;
    background-color: rgb(190, 190, 190);
    transition: 0.5s;
    position: relative;
    z-index: 60;
    width: 100%;
}

.BurgerMenu > .BurgerContent {
    height: 100%;
    width: 100%;
    display: flex;
    position: absolute;
    flex-direction: column;
    box-sizing: border-box;
    margin: 2rem;
}

.BurgerMenu > .BurgerContent > a {
    /* color: rgb(50, 50, 50); */
    color: black;
    box-sizing: border-box;
    position: relative;
}

And this is the corresponding JSX code:

<div ref={ref} className="wrapper">
  <div className="BurgerMenu">
    <div className="BurgerContent">
      {navItems.map((navItem) => (
        <a key={navItem.name} onClick={(e) => handleClick(navItem.to)(e)}>
          {navItem.name}
        </a>
       ))}
    </div>
  </div>
</div>

Answer №1

The div containing the two anchor tags is styled with a class called BurgerContent and is set to have an absolute position. This means that it will always be positioned absolutely in relation to its closest ancestor that is also positioned.

In this particular scenario, the closest positioned ancestor could either be the parent element with a relative position (the div with the class BurgerMenu), or if there are no other positioned ancestors, it would default to being positioned relative to the document body. Since both options result in similar positioning, you may not notice a visual difference.

It's worth considering whether using absolute positioning is the best approach for this situation.

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

Efficient ways to clear all input fields within a React div component

import "./App.css"; import { useState } from "react"; import { useSelector, useDispatch } from "react-redux"; import { addUser} from "./features/Users"; function App() { const dispatch = useDispatch(); const use ...

Using Redux action to pass a parameter in an axios request while utilizing hooks

I've been developing a React app with Redux (thunk). Within this table, I have a list of users: function DataUsers() { const users = useSelector((state: any) => state.userReducer.infos); const now = 60; const history = useHistory() ...

Upon launching npm start, an error message appeared stating "react-scripts: command not found"

My experience with cloning a React application onto my system was not as smooth as I had hoped. After running the necessary commands below: npm install -g create-react-app npm install --save react react-dom I excitedly proceeded to run: npm start To my ...

What is the best way to generate an array of imported images within a React Component?

I am looking to optimize the loading process for nearly a hundred images in my React component by importing them all via a single statement from another JavaScript file. However, before I can achieve this, I need to find a way to store all these images in ...

Is it possible to apply CSS based on a component's displayName?

Are you a CSS pro? I'm attempting to apply a class that will make all descendants of an element read-only, but for some reason the style isn't being applied as expected: #ComponentDisplayName * { -webkit-user-select: text; -moz-user-sel ...

Tips for detecting the end of a scroll view in a list view

I've encountered an issue with my scrollView that allows for infinite scrolling until the banner or container disappears. What I'm aiming for is to restrict scrolling once you reach the last section, like number 3, to prevent the name part from m ...

Is it possible to establish a standard view for the date/time input field, disregarding the user's

When working with a Django Form, I am incorporating a datepicker. While the solution may involve JS and HTML, my query remains specific. date_field= forms.DateField( input_formats=['%Y-%m-%d'], widget=forms.DateInput( format=& ...

Add a consistent typography style to all pages in NextJS

I am working on a nextjs application and have implemented a Google font in my app/layout.tsx file: The issue I am facing is that this font is only being applied on the / page and not on any other pages. Should the layout.tsx file apply to all child compon ...

Implementing Formik in React for automatic updates to a Material-UI TextField when blurred

Presently, I am developing a dynamic table where users can simultaneously modify multiple user details in bulk (Refer to the Image). The implementation involves utilizing Material-UI's <TextField/> component along with Formik for managing form s ...

Typescript is failing to perform type checking

I'm encountering an issue while trying to utilize TypeScript type checking with the following code snippet: abstract class Mammal { abstract breed(other: Mammal); } class Dog extends Mammal { breed(other: Dog) {} } class Cat extends Mammal { ...

Different ways to modify the underline and label color in Material-UI's <Select/> component

A while ago, I came across this useful demo that helped me change the colors of input fields. Here is the link: https://stackblitz.com/edit/material-ui-custom-outline-color Now, I'm on a quest to find a similar demo for customizing the color of selec ...

The specified property 'slug' is not found within the designated type 'ParsedUrlQuery | undefined'

I am faced with an issue in my code where I am attempting to retrieve the path of my page within the getServerSideProps function. However, I have encountered a problem as the type of params is currently an object. How can I convert this object into a stri ...

Is it possible to establish role-based access permissions once logged in using Angular 6?

Upon logging in, the system should verify the admin type and redirect them to a specific component. For example, an HOD should access the admi dashboard, CICT should access admin2 dashboard, etc. Below is my mongoose schema: const mongoose = require(&apo ...

Issue with retrieving URL parameters in Nextjs during server side rendering

Currently, I'm attempting to extract the request query, also known as GET parameters, from the URL in server-side rendering for validation and authentication purposes, such as with a Shopify shop. However, I am facing issues with verifying or parsing ...

Difficulty encountered when trying to use Bootstrap tooltip with Bootstrap icon

Attempting to implement bootstrap tooltips on bootstrap icons with the following code: <body> <script> const tooltipTriggerList = document.querySelectorAll('[data-bs-toggle="tooltip"]') ...

Primeng - Concealed dropdown values within a scrollable table header

Recently, I integrated Primeng p-table with a filter and frozen column feature (with one column being fixed while the others are movable). However, I encountered an issue with the select dropdown in the header. When I try to open the dropdown, the values a ...

Having trouble sending a POST request to a nested array in Express JS

Welcome, this is my first post here so feel free to point out any missing information or incomplete details in my question :) I am currently working on a project where I need to make a POST request to an array within my data structure called features: co ...

Searching for a post by content or title on Flask can be done by utilizing the search functionality built

I've created routes and forms, but when I tried to search, it showed "cannot be found." Here is my code: routes.py: @app.route('/search',methods=['GET','POST']) def posts_lists(): q = request.args.get('q') ...

The toggle button appears to be lacking in CSS styling

I'm trying to create a dropdown button using Bootstrap and ng-bootstrap in my Angular project. Here's the HTML I've written: <div ngbDropdown class="d-inline-block"> <button class="btn btn-outline-primary" id="dropdownBasic1" n ...

The "as" property in NextJS Link does not properly reload the page when opened

I recently started using NextJS and I have a question about its router. I want to link to a page, but I would like the URL to be different. <Link href="/About/About" as="/about-page"> <a> Who We Are <im ...