React dropdown menu that can be showcased by hovering the mouse

Why isn't the code below generating a dropdown menu with a switch on the menu as expected, and how can I troubleshoot and resolve this issue?

Css Style File:

/* Dropdown Button */
.dropbtn {
  background-color: #04aa6d;
  color: white;
  padding: 16px;
  font-size: 16px;
  border: none;
}

/* The container <div> - needed to position the dropdown content */
.dropdown {
  position: relative;
  display: inline-block;
}

/* Dropdown Content (Hidden by Default) */
.dropdown-content {
  display: none;
  position: absolute;
  background-color: #f1f1f1;
  min-width: 160px;
  box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
  z-index: 1;
}

/* Links inside the dropdown */
.dropdown-content a {
  color: black;
  padding: 12px 16px;
  text-decoration: none;
  display: block;
}

/* Change color of dropdown links on hover */
.dropdown-content a:hover {
  background-color: #ddd;
}

/* Show the dropdown menu on hover */
.dropdown:hover .dropdown-content {
  display: block;
}

/* Change the background color of the dropdown button when the dropdown content is shown */
.dropdown:hover .dropbtn {
  background-color: #3e8e41;
}

TypeScript Code:

import type { NextPage } from "next";
import styles from "../styles/header.module.css";
import Head from "next/head";

export const Header: NextPage = () => {
  return (
    <div>
      <Head>
        <title>Lamboghini</title>
        <meta name="description" content="Lamborghini" />
        <link rel="icon" href="/favicon.ico" />
      </Head>
      <div className={styles.dropdown}>
        <button className={styles.dropbtn}>Dropdown</button>
        <div className={styles.dropdown_content}>
          <a href="#">Link 1</a>
          <a href="#">Link 2</a>
          <a href="#">Link 3</a>
        </div>
      </div>
    </div>
  );
};

Answer №1

Your CSS shows

/* Display the dropdown menu when hovered */
.dropdown:hover .dropdown-content {
  display: block;
}

However, your component is utilizing dropdown_content (underscore instead of hyphen)

<div className={styles.dropdown_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

Text alignment validation in jQuery

utilizing the validation capabilities of the jQuery validation plugin check out: http://jsfiddle.net/Kn3v5/205/ <script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.js"></script> <div> <form id ...

Using mailR: Referencing a Dataframe in the Body of an Email

Can someone please help me figure out how to reference a character dataframe using mailR in the body of an email? I would like to include a message like "Today's profit was x," but I'm not sure how to do it. ...

Are there any tools available for selecting fonts to use in an input form for users?

I am currently seeking a font picker tool that can be integrated into my web project to allow users to select from a variety of fonts. I have implemented a basic code using radio buttons, which seems to be functioning as intended: <label style="font-fa ...

How about implementing a 'thumbs up' feature on every post?

I'm relatively new to SQL and PHP and have successfully set up a database where I can input entries through an HTML form. However, I am struggling with implementing a 'like button' feature that will increment a counter for each specific post ...

The CSS styles are not recognized by the Windows 2003 server

After deploying my webapp, which was created using asp.net, to a testing server (Windows 2003 SP2, IIS6), I encountered an issue. When I accessed the default page, none of the CSS styles were applied. Only plain text or formatting from the .aspx file was v ...

Keep fancybox items in their designated spot

When the window is opened at full size, everything looks fine. However, when you resize the window horizontally, the thumbnails shift and disappear. I want them to remain fixed in their position like the large pop-up image so that users can still see them ...

JSON-based Material UI Dropdown Selector

I'm having trouble populating a Material UI Drop down with JSON Data. Can someone help me identify the issue? Below is the code snippet that contains the JSON data and the relevant code. const json = { ResponseMetadata: { RequestId: "1B29B45E145594A ...

OnePageCheckout may result in empty boxes being displayed due to OneStepCheckout CSS styling

Seeking advice for an issue with the Magento OneStepCheckout module. Upon checkout, there are three columns: customer data (working fine), payment options (selectable via checkbox), and details about the chosen payment method. Unfortunately, the informati ...

Excessive indentation detected within the website's formatting

There seems to be an issue with the mobile version of the website, possibly related to flexbox, SVG, or width settings that are unclear to me. Inspecting with Devtools reveals indents from the SVG and text itself. Check out the website here My goal is to ...

The page is constantly updating on its own

In my React app, the App component checks for a token in local storage upon loading. If a token is found, it is verified. If the token is valid, the user is directed to the dashboard; otherwise, they are taken to the login page. The issue I am facing is ...

Resetting component state in React Native is essential for maintaining the correct

I need to reset the state of specific states without affecting others. When a button is clicked, the values of present_count, total_count, present, and total should all be restored to their original state (0), while keeping the state of subjects and text u ...

What is the best way to make a HTML link stand out by adding blinking superscript text using a custom blink effect?

Can you please help me with a code snippet to emphasize an html link by adding superscript text "new" surrounded by a circle or star symbol? I would like the "New" text in superscript to blink as well, drawing attention from users. Here is the HTML code s ...

What is the method for altering the date format of a published article?

I am looking to modify the date format of a published post in WordPress. Currently, the date format is <?php the_time('m.d.y'); ?></div>, which appears as "1.20.2018". My goal is to change it to "January 20, 2018". Can anyone guide ...

A problem arose during the process of mapping an array of objects in react - There was a parsing error: An unexpected token was encountered, expecting a comma (13:9) with eslint

I am currently working on mapping an array of objects containing data, but I am encountering an error that I am unable to identify in the code. Please disregard the console.logs as they are for my own reference. https://i.sstatic.net/vbpLX.png import Reac ...

Retrieve the value from an input tag that is only displayed based on a condition using *ngIf

In my HTML form, I have implemented conditional visibility of input fields based on the radio button selection using *ngIf. <table> <tr> <td><label>name</label></td> <td><input #name />&l ...

Customizing the Drawer component in Material-ui with media queries

I'm trying to adjust the width of the <Drawer> component to be 50% of the screen on web and 90% on mobile. Unfortunately, I'm having trouble getting the media query to work with material-ui components. Is there anyone who can assist me wit ...

Ways to prevent the spread of an event from the main div to the nested div

I need assistance in preventing an event from propagating from a parent div to a child div within my HTML. Below is a snippet of the code I am working with: <div> <div id='categoryList'> <div class='listed-category&apos ...

Upon clicking, a pop-up modal will display

I've set up a webpage with multiple cards displayed on it. My goal is to have a pop-up window appear when a user clicks on each card. Initially, I just want to ensure the basic functionality of the pop-up, even if the content remains the same. Althoug ...

When using the "top" property in position-absolute, the child element may exceed the boundaries of the parent element

My child element is overflowing its parent when I apply "top: random pixel" to it. It seems to be using the top position relative to the body of the page. // HTML <div class="movie-list"> <div class = "inn ...

What is the best way to implement a responsive layout in Bootstrap 5?

<body> <header> <nav class="navbar navbar-expand-md navbar-light" style="background-color:#f6b319"> <div class="container-fluid"> <div class="navba ...