Unable to display hamburger icon when utilizing React.js

The hamburger icon is not appearing on mobile, even though it seems to be working. However, when I click on the icon, it does not show up on mobile devices.

Here is my HTML code:

.hamburger {
  cursor: pointer;
  height: 16px;
  margin: 10px 0 -1px 10px;
  position: relative;
  top: 4px;
  transform: scale(1.1);
  width: 20px;
  z-index: 100
}

@media (min-width:1280px) {
  .hamburger {
    display: none;
    margin: 18px 30px 0 0
  }
  .hamburger.active {
    display: block
  }
}

.hamburger.active span {
  background: #fff
}

.hamburger.active span:first-child {
  left: 50%;
  top: 6px;
  width: 0
}

.hamburger.active span:nth-child(2) {
  transform: rotate(45deg)
}

.hamburger.active span:nth-child(3) {
  transform: rotate(-45deg)
}

.hamburger.active span:nth-child(4) {
  left: 50%;
  top: 6px;
  width: 0
}

.hamburger span {
  background: #1a1a1a;
  border-radius: 2px;
  display: block;
  height: 2px;
  left: 0;
  position: absolute;
  transform: rotate(0deg);
  transition: transform .25s ease-in-out;
  width: 100%
}

.hamburger span:first-child {
  top: 0
}

.hamburger span:nth-child(2),
.hamburger span:nth-child(3) {
  top: 6px
}

.hamburger span:nth-child(4) {
  top: 12px
}
<button class="showMobileMenu inline-block bg-ubx-red text-xxl py-4 px-0 cursor-pointer outline-none focus-outline-none z-50 relative outline-none focus-outline-none text-white w-10 h-8 mobiMenuToggleIsActive xl-hidden" @click="${this._handleShowMenuClick}">
            <div className="hamburger hamburger-btn">
              <span></span>
              <span></span>
              <span></span>
              <span></span>
            </div>
          </button>

What could be the issue here?

Answer №1

Please consider adopting this method


 <button class="showMobileMenu inline-block bg-ubx-red text-xxl py-4 px-0 
  cursor-pointer outline-none focus-outline-none z-50 relative outline- 
  none focus-outline-none 

text-white // the issue with this tailwind class is that the white icon blends in with the white background w-10 h-8 mobiMenuToggleIsActive xl- hidden" @click="${this._handleShowMenuClick}"> close


    .hamburger {
  cursor: pointer;
  height: 16px;
  margin: 10px 0 -1px 10px;
  position: relative;
  top: 4px;
  transform: scale(1.1);
  width: 20px;
  z-index: 100;
  display: none; /* Hidden initially */
}

@media (max-width: 1280px) {
  .hamburger {
    display: none;
    margin: 18px 30px 0 0;
  }
  .hamburger.active {
    display: block;
  }
}

.hamburger.active span:first-child {
  left: 50%;
  top: 6px;
  width: 0;
}

.hamburger.active span:nth-child(2) {
  transform: rotate(45deg);
}

.hamburger.active span:nth-child(3) {
  transform: rotate(-45deg);
}

.hamburger.active span:nth-child(4) {
  left: 50%;
  top: 6px;
  width: 0;
}

.hamburger span {
  background: #1a1a1a;
  border-radius: 2px;
  display: block;
  height: 2px;
  left: 0;
  position: absolute;
  transform: rotate(0deg);
  transition: transform 0.25s ease-in-out;
  width: 100%;
}

.hamburger span:first-child {
  top: 0;
}

.hamburger span:nth-child(2),
.hamburger span:nth-child(3) {
  top: 6px;
}

.hamburger span:nth-child(4) {
  top: 12px;
}

Give this a try, it should work for your needs.

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

Having trouble executing: "npm start" on React platform

Upon attempting to run my project using npm start, I encountered an error message that is somewhat unclear to me: react-app-rewired start The "path" argument must be of type string or an instance of Buffer or URL. Received undefined npm ERR! code ELIF ...

Analyzing registration details stored in an array against user login credentials

With two buttons available - one for sign up and the other for log in, my goal is to gather input form values from the sign-up section into an array. Following this, I aim to compare the user input from the sign-up with that of the log-in, informing the us ...

Tips for fixing the error "Unhandled error: state.set is not a function"

My code is utilizing immutable.js in the reducer, but I keep encountering an error stating 'state.set is not a function'. Interestingly, when I modify the code to exclude immutable, the error disappears. import React from 'react'; impo ...

The iPhone display scaling issue is causing difficulty viewing the entire website

Currently experiencing difficulties with a page that lacks sufficient content, resulting in a smaller height. As a result, the iPhone is scaling the page and cutting off the full menu bar (960px wide). I attempted to set a minimum height using a media quer ...

Troubleshooting issue with image dimensions in Angular within CKEditor content

One issue I am facing is with CKEditor, where images inserted into Rich Text Fields have their height and width attributes set in a CSS style tag. For example: <img alt="" src="https://something.cloudfront.net/something.jpg" style="height:402px; ...

What is the process for attaching a right ribbon label onto a card in Fomantic UI components?

I am completely new to Fomantic (and web development in general) and I'm attempting to create a website featuring a card with a ribbon label on the right side. I saw similar designs in the documentation where they used a segment instead. However, when ...

When utilizing React router v5, the exact property in a route may not function as expected if there is a

I am attempting to structure routes like Vue.js in an array format: // routes.js export const routing = [ { path: "/setting", component: Setting, }, { path: "/", co ...

Tips for Customizing Dialogs with CSS Classes in mui5 Using Emotion/Styled

When attempting to customize the styling of a mui Dialog, I encountered an issue where it wouldn't accept className even when placed inside PaperProps. While inline styles worked, my preference was to import styles from a separate stylesheet named Sty ...

What is the best way to insert a <dv> element following a <Typography> component in the provided code?

After learning React, I have attempted in various ways to get this code snippet to work. I referred to a question on Stackoverflow as well as the HTML div documentation The goal is to have the text and link displayed in a horizontal line, not vertically s ...

The error message displayed by create-react-app is: "The node engine specified for this module is not compatible. It is expecting a version greater than or equal to 6.9.0 and less than 7.0.0, or greater than or equal to 8.9.0."

When attempting to use npm init react-app my-app or npx create-react-app my-app, I encountered an issue despite having node -v v8.2.1. Here is the output on my console: > [1/4] ...

Display a Bootstrap table that includes a visible vertical scrollbar

Creating a basic HTML page using Bootstrap library can be tricky when trying to incorporate a fixed header and a scrolling table. When simply adding a navbar and a table, the table ends up being positioned beneath the navbar, making it impossible to scroll ...

Alert: Next.js 13 console error detected

Currently, I am utilizing Next js 13 for the development of a website. However, I have encountered this warning in the console: The resource http://localhost:3000/_next/static/chunks/polyfills.js was preloaded using link preload but not used within a few s ...

Text does not conform to image boundaries

I've been having trouble with this issue and despite trying various solutions, I haven't been able to figure it out. I'm new to this so it's likely something very simple that I'm overlooking... .container { width: 80%; margin: ...

Tips for aligning an image to the left inside a paragraph

Currently working on my ecommerce store homepage, placed just below the carousel is an image with the heading "I Wish I Were Knitting..." accompanied by a paragraph that seems to be wrapped around it. I have added a float class to the image tag within the ...

Adjustments in Spacing for Text with Significant Digits

It has come to my attention that in the United States, large numbers are often formatted with a comma between thousands, like so: $1,000,000.00. Here in South Africa, using a comma as a thousands separator is not standard practice, as it is more commonly u ...

Issues with user authentication on the front-end, encountering problems with CRUB and spring security

I have been struggling for 4 days trying to find a solution. My backend is on spring boot and frontend is on react. How can I create a login system and session on my frontend page? I have 2 RestControllers for testing purposes. @GetMapping("/protected") ...

The issue of sluggishness in Material-UI when expanding the menu is causing delays

Watch Video Having trouble with the behavior of the Menu opening and closing similar to this example. The text seems slow to change position. Any ideas why? This is the devDependencies configuration I am using in webpack. "devDependencies": { ...

I am unable to access a certain piece of data directly, as I must use an intermediary variable in the process

As someone who is just starting out in programming, I may not have the best questions. Please bear with me if I am taking up your time unnecessarily. I have a query regarding the usage of labels indirectly in DatatoBarChartJS (using a "label") that confuse ...

Creating a div that becomes fixed at the top of the page after scrolling down a certain distance is a great way to improve user experience on a

I am struggling to create a fixed navigation bar that sticks to the top of the page after scrolling 500px, but without using position: fixed. Despite trying various solutions, none seem to work due to the unique layout of my navigation bar. Strangely enoug ...

Strategies for aligning a div element in the middle of the screen

Positioned in the center of the current viewport, above all other elements. Compatible across different browsers without relying on third-party plugins, etc. Can be achieved using CSS or JavaScript UPDATE: I attempted to use Javascript's Sys.UI.Dom ...