Why is the hamburger and cart icon positioned below the hamburger menu when opened?

During my journey of learning responsive design, I encountered an issue where the hamburger and cart icon appeared below my hamburger menu instead of the top-right corner. I am unable to pinpoint the problem within my code.

To provide better clarity, I have attached an error image: error-image

The expected layout should have both the hamburger icon and cart icon positioned in the top-right corner as depicted in the shared image.

This is the code snippet in question:

    <div className="navbar">
      <a href="#" className="navbar-logo">
        Redux Store
      </a>
      <ul className={`navbar-menu ${menuActive ? "active" : ""}`}>
        <li>
          <a href="#">Home</a>
        </li>
        <li>
          <a href="#">Shop</a>
        </li>
        <li>
          <a href="#">About</a>
        </li>
        <li>
          <a href="#">Contact</a>
        </li>
      </ul>
      <Link className="cart-icon" to="/cart">
        🛒
        <div className="cart-quantity">3</div>{" "}
        {/* Replace '3' with the actual quantity */}
      </Link>
      <div
        className={`hamburger-menu ${menuActive ? "active" : ""}`}
        onClick={() => setMenuActive(!menuActive)}
      >
        <span></span>
        <span></span>
        <span></span>
      </div>
    </div>

css

.navbar {
  background-color: white;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  padding: 15px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

...

Answer â„–1

It seems like the issue lies within your HTML structure. By implementing the following structure, you may be able to resolve the problem:

<div className="navbar">
  <a href="#" className="navbar-logo">
    Redux Store
  </a>
  <div className={`hamburger-menu ${menuActive ? "active" : ""}`} onClick={() => setMenuActive(!menuActive)}>
    <span></span>
    <span></span>
    <span></span>
  </div>
  <ul className={`navbar-menu ${menuActive ? "active" : ""}`}>
    <li>
      <a href="#">Home</a>
    </li>
    <li>
      <a href="#">Shop</a>
    </li>
    <li>
      <a href="#">About</a>
    </li>
    <li>
      <a href="#">Contact</a>
    </li>
  </ul>
  <Link className="cart-icon" to="/cart">
    🛒
    <div className="cart-quantity">3</div>{" "}
    {/* Replace '3' with the actual quantity */}
  </Link>
</div>

Consider adjusting this CSS property:

.cart-icon {
    order: 2;
}

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

Maintain room within React elements for a better layout

When retrieving a string with spaces from my backend service and logging it in the render method, I noticed that the raw string is displayed correctly with spaces. However, when the element is rendered on the screen, the spaces seem to be missing. For ex ...

Tips for personalizing text and icon colors in the TableSortText element of Material-ui

My Goal: I aim to empower users with the ability to apply customized styles to my EnhancedTable component by utilizing a styles object containing properties like headCellColor, headCellBackgroundColor, bodyCellColor, bodyCellBackgroundColor, and more. The ...

Leveraging ng-click and ng-hide/show directives within ng-repeat in Angular

I have a simple Single Page Website built with Angular. I utilized ng-repeat to generate content on the main page, where each item is an image. I am looking to create an alternate view for each image to display more details. I have implemented this feature ...

Preventing non-breaking spaces and characters from being added in Jquery Mobile

When developing an application using jQuery Mobile, I encountered a strange issue on my homepage. In between the listview, this code snippet appeared: &nbsp;&nbsp;&nbsp;&nbsp; But without the following meta tag: <meta http-equiv="Cont ...

What is the best way to interact with the dynamic Twitter follow button using Selenium and Python?

Trying to interact with Twitter's follow button can be challenging, especially when it is dynamic and has attributes that are not well-documented in the Selenium documentation. Below is a snippet of the HTML code for the button: Below you will see my ...

Eliminate the need for background video buffering

I have a piece of code that I'm using to remove all the created players for my video elements. The code works fine, but I'm facing an issue where the video keeps buffering in the background after it's changed via an ajax call success. Can yo ...

Mistakes found in next.config.js when using the next-compose-plugins package

I'm encountering issues with Next.js and next-compose-plugins in my next.config.js file. It's throwing errors that I can't seem to resolve even after reinstalling all node packages. The specific errors I'm facing are: "The root va ...

Utilize CSS to prioritize the image and ensure it is responsive

I'm utilizing the 'featurette' feature in bootstrap. Currently, the page displays text on the left and an image on the right. As you reduce the browser size, they stack on top of each other, with the text appearing above the image. How can I ...

Press a button to instantly switch the image in Chrome and Safari with no transition

I am working on an interface that contains multiple buttons. Whenever a user clicks on a button, I am using jQuery to toggle the button image. The code looks something like this: $(".button").click(function() { $(".button").html("<img src="...">" ...

Tips for creating improved CSS ID rules

Currently, I am in the process of learning HTML and CSS and have a question regarding writing rules for multiple IDs. Is it possible to write rules that apply to several IDs in order to achieve my desired outcome? <!-- language: lang-css--> #menu- ...

Using Material-UI to implement a Link component from the react-router library

I'm having trouble integrating the <Link/> component into my material-ui AppBar. Here is my navigation class: class Navigation extends Component { constructor(props) { super(props) } render() { var styles = { appBar: { ...

What is the functionality of intro.js?

Currently, I am utilizing an onboarding tour at my.bonify.de that provides a similar experience to introjs. The way we have implemented this feature is quite unattractive, using a cutout div with a very large box-shadow. We are looking to enhance it by in ...

The CORS policy in React and Go has blocked access to 'https://abcde.eu.ngrok.io' from 'https://webpage.com'

I've been attempting to send a Post request from my React frontend to a Golang backend like this: const SendDataToBackend = async (values) => { try { const response = await fetch(`${API_URL}`, { method: 'POST', ...

The window.open function is returning a null value after attempting to open the specified

Is there a way to prevent users from opening more than one IFrame window for my application? I have included the following code: <html> <head> <title>Testing Window Opening Limitation</title> <meta http-equiv="Content-Type" cont ...

Discovering elements using Selenium in a JavaScript popup box

The issue at hand is rather straightforward. I am faced with the task of clicking on an element within a popup that has been dynamically generated by JavaScript code. The challenge arises as the page is solely accessible in Internet Explorer and the elemen ...

Learn how to hide a bar after clicking the "I agree" button with the help of Bootstrap

click here to see imageIs there a way to make that bar disappear once the user clicks "I agree"? I've searched through Bootstrap documentation but couldn't find a solution. Please assist. Below is the code snippet: <div id="cookie-message" cl ...

Upon submitting the form, an Ajax call will execute and transfer data to a distinct views.py template

I'm currently in the process of developing a web application with Django. On the index page, I have implemented a search function. The goal is to trigger an AJAX call when a user submits the form. This AJAX call should gather all the necessary data fr ...

Incorporating photos within the layout of a Twitter Bootstrap grid

Looking to showcase images like the ones found here: https://i.stack.imgur.com/eD4GD.jpg These images are original and come in various sizes. I want a hover effect that includes blur, fogging effects, and text placed in the middle of the picture. Check ou ...

Facing an issue where the data returned in React is showing up as undefined

I am currently facing an issue with passing data down to a component using react router. After confirming that the endpoint is functioning correctly, I have ruled out any server-related problems. Here is the function responsible for fetching page data bas ...

An incessant stream of onclick events is being triggered

My HTML code consists of a jQuery script and a button that triggers a function to display random answers. However, after clicking the button once, the answers cycle automatically without any input. I want each click to show a different answer. What could ...