The z-index property seems to be disregarded

I'm facing an issue with my navigation dropdown menu. I want the dropdown items to appear from behind the menu, but they always come from the top. I've tried adjusting the z-index but it doesn't work. I've checked similar problems online, and most of them were due to elements not being positioned correctly, but mine are. Here's the HTML for the menu component (<MenuItem />)

 <div>
                <div className={styles.dropdown}>
                    <div className={styles.dropbtn}>Bio</div>

                    <div className={styles.dropdownContent}>
                        <Link href="/biography">Biography</Link>
                        <Link href="/albums">Discography</Link>
                        <Link href="#">TV/Films</Link>
                        <Link href="/games">Video Games</Link>


                    </div>
                </div>
                <div className={styles.dropdown}>
                    <div className={styles.dropbtn}>Media</div>

                    <div className={styles.dropdownContent}>
                        <Link href="/media/videos">Videos</Link>
                        <Link href="/media/gallery">Photos</Link>
                        <Link href="#">Music</Link>
                    </div>

                </div>
                <div className={styles.dropdown}>
                    <div className={styles.dropbtn}>Pedagogy</div>

                    <div className={styles.dropdownContent}>
                        <Link href="/methods">Methods</Link>
                        <Link href="#">Internet</Link>
                        <Link href="#">Journals</Link>
                    </div>


                </div>

                <LanguageSwitcher/>


            </div>

Here's the code for my top menu

<nav className={styles.menu}>
            <Link href={'/'}>
                <div className={styles.logoContainer}>
                    <div className={styles.logo}>Chris Rime<Image
                        src={'/images/bg/waveform.svg'}
                        width={100}

                    /></div>
                </div>

            </Link>


    


            <div className={styles.menuContainer}>
                {!matches ? (
                    <Image src={'/images/icons/musicburger.svg'} style={{cursor: 'pointer'}} width={30}
                           onClick={() => setOpened((o) => !o)}
                    />
                ) : (
                    <div className={styles.menuItems}>
                        <MenuItems/>
                    </div>


                )}


            </div>

        </nav>

And here's my CSS styles

.menu {
    position:fixed;
    z-index:5;
    top:0;
    width:100%;
    height:75px;
    display: flex;
    gap: 20px;
    justify-content: flex-end;
    transition: 0.4s;
    background-color: var(--secondary);
    border-bottom: 1px solid var(--accent);

}


.dropdown {
    /*position: relative;*/
    display: inline-block;
    transition: 0.3s;

}

.dropdownContent {
    animation: dropBack 0.5s cubic-bezier(0.250, 0.460, 0.450, 0.940) both;
    display: none;
    position: absolute;
    background-color: var(--accent);
    width:100vw;
    left:0;
    box-shadow: rgba(0, 0, 0, 0.09) 0px 2px 1px, rgba(0, 0, 0, 0.09) 0px 4px 2px, rgba(0, 0, 0, 0.09) 0px 8px 4px, rgba(0, 0, 0, 0.09) 0px 16px 8px, rgba(0, 0, 0, 0.09) 0px 32px 16px;
    z-index:6

}




.dropdownContent  a {
    color: var(--primary);
    padding: 12px 16px;
    text-decoration: none;
    transition: 0.3s;
    display: block;

}



.dropbtn {
    height: 100%;
    color: white;
    width:100%;

    padding: 16px;
    border: none;
    cursor: pointer;
    transition: 0.3s;
    border-radius: 0 10px 0 10px;
    font-size : 30px;
    list-style-type: none;
    font-family: 'Nanum Gothic', sans-serif;
    display: flex;
    justify-content: space-around;
    /*align-items: center;*/

}

.dropbtn span {
    font-size: 0.4em;
    padding: 10px;
}

.dropdownContent  a:hover {
    background-color: var(--accent)

}

.dropdown:hover .dropdownContent  {
display: flex;
    justify-content: flex-end;
transition: top 1s linear;
    animation: dropdownContent 0.6s cubic-bezier(0.250, 0.460, 0.450, 0.940) both
}

I've set up a codepen to demonstrate the issue

https://codepen.io/Altho/pen/zYpLMzj

Answer №1

To enhance the design, consider setting the parent class to position:"relative" and the interior class to position:"absolute'. Don't forget to add z-index as needed.

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

The combination of DOMDocument and DOMXPath is a powerful duo

I am currently working on converting CSS to inline using DOMDocument and DOMXPath. However, I'm encountering an issue where the HTML I provide is not being recognized as valid XML. Is there a way for me to configure these functions to ignore unknown ...

Applying a class change in Vue.js upon mounting

How can I make a button element with a .hover property trigger the hover animation as soon as the page loads? I want to apply a class to the button when the page is mounted and then remove it later. What is the best approach for this? I considered using a ...

Encountered a code 405 error while attempting to make a request to the controller API in an ASP.NET Core React application using Axios

Currently, I am developing a basic application using React and ASP.NET Core where I need to add records to the database utilizing EntityFramework Core. The application consists of a straightforward form with a textbox and a button. However, upon clicking t ...

Each row in an Ant Design table should have a checkbox for easy selection

I am looking to add a checkbox in each column of a row within the Ant Design table. For example, in the sample sandbox provided, instead of displaying John Brown, 32, and New York No. 1 Lake Park, I want to have checkboxes there. Can someone assist me with ...

Utilize React Router to direct users to a specific page from a search form in React

Anticipated: The goal is to have a search form available on every page to display fetched data upon submission. Reality: Upon form submission, a TypeError is encountered stating that dataItems is undefined. Below is the code for my app component: class ...

The content inside the bootstrap modal is not visible

My goal is to trigger a modal window when a specific div is clicked using bootstrap modal. However, upon clicking the div, the screen darkens but the modal body fails to appear. Code: <html> <head> <title></title> ...

Clicking on the menu to reveal the dropdown options using JavaScript

I have created a drop-down menu for my website, but I am facing an issue. When I click on the links again, it does not work properly because I lack expertise in JavaScript. I would appreciate any help and suggestions from all of you. Thank you for your tim ...

DataGrid Component: Implementing a Button for Deleting Rows

I am currently developing a React component with MaterialUI, incorporating a Datagrid to manage a queue of files. The layout resembles this: https://i.sstatic.net/oh0GH.png One functionality I'm focusing on is when the user clicks on the three dots a ...

Trouble with Varnish Cache

We are currently in the process of developing a website using React and Redux. Recently, we implemented a Varnish cache on our API. While testing the API on Postman, everything appears to be functioning properly. However, when accessing our website, we are ...

Tips for avoiding the automatic conversion of 0.00 to 0.0 by prettier eslint

I am working on ComponentA and need to set the default value to 0.00. However, the formatting by prettier eslint changes it from 0.00 to 0.0 in the component file. How can we prevent this from happening? export const ComponentA = ({ validate, isRequired }) ...

Encountering 500 Internal Server Errors when navigating certain routes using Next Js

Live Demo Upon deploying a Next JS project to Vercel, I encountered an issue where certain page paths like xxx.vercel.app/first or /second resulted in a "500: Internal Server Error". Strangely, these errors only occur on these specific routes. Despite no ...

How can the CORS issue be resolved when sending a form from a client to an AWS API gateway function?

Within my front end React application, I am looking to implement a contact form that will submit data to a Lambda function via an API Gateway with a custom domain attached. The frontend operates on the domain dev.example.com:3000, while the API Gateway is ...

Modifying the dimensions of an image within a :before pseudo-element

Currently, I am working on designing a mobile menu and encountered an issue with resizing the image of the hamburger menu button. Despite attempting to adjust it by following some suggestions such as this one: How to Resize Image Using CSS Pseudo-elements ...

Transform the inline style attributes found in the HTML code into CSS styling

After creating a webpage using Bootstrap Studio, I realized that all the style attributes are inline and I want to move them to a separate CSS file. However, I am facing difficulty in doing so as when I add an image using 'background-image:url('i ...

What is the best way to apply a CSS class to a ComponentRef that has been generated in Angular 5

I am attempting to dynamically add a CSS class to a component right after its creation by utilizing ViewContainerRef and ComponentFactoryResolver. My goal is to determine the class based on which other Components have already been added to myViewContainerR ...

Utilizing the handleChange method to manage multiple input fields

It is important to me that the function handleChange only updates the input value that is being changed. Specifically, if I modify the 'firstName' input, I want only that state to be updated, and the same applies to the 'lastName' input ...

Toggle the visibility of items based on the user's login status

Below is the code snippet for when the user is logged out: <div class="fusion-secondary-main-menu"> <div class="fusion-row"> <?php avada_main_menu(); ?> <?php avada_mobile_menu_search( ...

Side Menu with Fixed Position Created with Tailwind CSS

Can anyone help me create a social media sidebar that stays fixed on the bottom right side of the screen, regardless of its size? Currently, the sidebar moves when I scroll down, but I want it to remain in place. How can I achieve this fixed positioning? ...

Setting background colors for classes based on an array

I have a total of six div elements on a single page, all sharing the same class. My goal is to give each one a unique color from an array I have prepared. I want to avoid any repetition of colors among these divs. Currently, I have managed to assign backg ...

Having trouble getting npm install @material-ui/core to work properly

I'm facing an issue while trying to set up material ui on my project. The following error is appearing: npm ERR! code ERESOLVE npm ERR! ERESOLVE unable to resolve dependency tree npm ERR! npm ERR! While resolving: <a href="/cdn-cgi/l/email-protecti ...