How can I modify the background color of the hamburger menu?

I attempted to modify the background color of the hamburger icon from black to yellow, but unfortunately, I couldn't achieve it. Here's what I tried:

//hamburger 
$(".hamburger").toggleClass("is-active");
var $hamburger = $(".hamburger");
  $hamburger.on("click", function(e) {
    $hamburger.toggleClass("is-active");
    // Implement additional functionality here for opening/closing a menu
  });
.hamburger{
  background-color: yellow;
}
 <link href="https://cdn.rawgit.com/jonsuh/hamburgers/0aedeec9/dist/hamburgers.css" rel="stylesheet">

<link href="https://fonts.googleapis.com/css?family=Oswald" rel="stylesheet">
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>


 <button class="hamburger hamburger--emphatic is-active" type="button" id="clickme">
  <span class="hamburger-box">
    <span class="hamburger-inner"></span>
  </span>
</button>

Answer №1

To change the color without using !important, target the inner children by specifying a custom parent class (in this case, the .hamburger class).

This method will override the hamburger.css styles without the need for using !important, keeping your code clean.

.hamburger1 .hamburger-inner,
.hamburger1 .hamburger-inner::before,
.hamburger1 .hamburger-inner::after {
  background-color: yellow;
}

// Toggle active class for hamburger button with class name "hamburger1"
$(".hamburger1").toggleClass("is-active");
var $hamburger1 = $(".hamburger1");
$hamburger1.on("click", function(e) {
  $hamburger1.toggleClass("is-active");
  // Add additional functionality here, like opening/closing a menu
});

// Toggle active class for hamburger button with class name "hamburger2"
var $hamburger2 = $(".hamburger2");
$hamburger2.on("click", function(e) {
  $hamburger2.toggleClass("is-active");
  // Add additional functionality here, like opening/closing a menu
});
.hamburger1 .hamburger-inner,
.hamburger1 .hamburger-inner::before,
.hamburger1 .hamburger-inner::after {
  background-color: yellow;
}

.hamburger2.is-active .hamburger-inner,
.hamburger2.is-active .hamburger-inner::before,
.hamburger2.is-active .hamburger-inner::after {
  background-color: yellow;
}
<link href="https://cdn.rawgit.com/jonsuh/hamburgers/0aedeec9/dist/hamburgers.css" rel="stylesheet">

<link href="https://fonts.googleapis.com/css?family=Oswald" rel="stylesheet">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>


<button class="hamburger hamburger1 hamburger--emphatic is-active" type="button" id="clickme">
  <span class="hamburger-box">
    <span class="hamburger-inner"></span>
  </span>
</button>

<h3>If you want an onclick event:</h3>

<button class="hamburger hamburger2 hamburger--emphatic " type="button" id="clickme2">
  <span class="hamburger-box">
    <span class="hamburger-inner"></span>
  </span>
</button>

Answer №2

When incorporating an external CSS file, it is important to remember to insert your customized CSS code and ensure that it includes the following:

.hamburger-inner, 
.hamburger-inner::before,
.hamburger-inner::after {
  background-color: yellow;
}

By doing so, you will be all set for success.

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

What's a way to pass a PHP variable directly to Javascript without using AJAX?

In my setup, I've implemented a JavaScript code that validates and sends the 'artwork' file to a PHP script on my server. This PHP script also performs its own checks for redundancy before writing the file to /uploads directory. The challen ...

Displaying several modals with a backdrop on top of one another using Bootstrap

My issue involves two modals: one that displays appointment information with a delete button, and another that serves as a warning before deleting. I want the delete-warning modal to overlay a backdrop on the modal beneath it, graying it out. However, both ...

Starting a typescript class with an already existing object - a step-by-step guide

Although my question may seem similar to previous ones, I have not found the answer I am looking for, so I am posting it here. Here is my example: Class A{ id:number; name:string; } Class B{ id:number; name:string; age:number; grade:number; } ...

Personalizing bootstrap tabs

I'm currently working on a project that requires implementing custom-style tabs. I'm facing challenges in customizing the borders of the tabs, particularly rounding the red bottom border and adding space between the right border and bottom border ...

Symfony along with React router have encountered an error: route not found

In my current project, I am working with Symfony3 and integrating React.js along with react-router to create a bundle. One issue I have encountered is that when using the routing in React, if I refresh the page, the Symfony routing module displays 'N ...

Creating a set width for the input-group-append division in Bootstrap 4

I am currently utilizing the power of Bootstrap 4's input group feature to position an icon next to an input field. My goal is to set a fixed width of 40px for the div containing the input-group-append (which houses the icon). According to the offici ...

Grab and deliver the particular tab that is currently in view

Within my background.js file, I am aiming to capture a specific area within a div. Here is a snippet of my code: function main() { chrome.tabs.query( {'active': true}, check_tab ); } function check_tab( tabs ) { for (i = 0; i < tabs. ...

Can you explain the difference between synchronous and asynchronous loading?

After exploring this website, I have learned that when using CommonJS, the browser loads files one by one after downloading them, which can lead to dependencies slowing down the process. However, with AMD, multiple files can be loaded simultaneously, all ...

Having trouble running the script, chrome error with message passing?

I've hit a roadblock while working on my Chrome extension and could use some assistance. The main issue I'm facing is getting the script to run when activated by the user through an on/off switch in the popup window. It seems like there might be ...

Leveraging packages obtained from npm repositories

Recently, I came across this guide about React that included a paragraph that left me puzzled. According to the guide, CommonJS modules (found in npm) cannot be directly used in web browsers due to technical limitations. Instead, you need a JavaScript " ...

Tips on enhancing the blur effect on hoverizr

Hello, I'm looking for assistance in increasing the blur effect using Hoverizr.min.js. I currently have code that blurs an image, but I'd like to make it blur even more. The image dimensions are approximately 1200px in height and 700px in width. ...

What are the best techniques for implementing opacity in styled components within react-native?

Trying to achieve a lighter background color using opacity in react-native with styled-components. I'm looking to make the background appear faded by adjusting the opacity level, but nothing seems to happen when I apply my code. Any suggestions on h ...

Generating navigation links with search queries

Embarking on the journey of incorporating pagination alongside user-defined search parameters has left me puzzled. I have a good grasp on pagination implementation without user input, but once user input factors in, confusion sets in. I find myself at a lo ...

Retrieve the identifier of the higher-order block when it is clicked

When I have a parent block with a nested child block inside of it, I expect to retrieve the id of the parent when clicked. However, the event target seems to be the child element instead. Is there a way for JavaScript to recognize the parent as the event ...

Add a CSS and jQuery hover effect to display text over an image, requiring users to click twice on their mobile device

I have a bunch of panels for different categories that change the background image when hovered over, display some introductory text, and lead to a URL when clicked. However, on mobile devices, you need to tap the panel twice to activate the URL. What I&a ...

Implementing a fixed div with jQuery scrolling

I need the left div to stay in sync with the scrolling content. However, there is a challenge because this div is taller than the screen. I want the user to be able to see the bottom of the left div when they reach the bottom of the page. My solution invo ...

Ensuring that jQuery(document).ready(function() contains the appropriate content

Recently, I've been attempting to integrate a javascript gallery into my WordPress site. However, I'm encountering some confusion regarding what needs to be included in the .ready(function) to successfully run the gallery. The original jQuery fun ...

Alternative names for Firefox's "error console" in different browsers

Are there similar tools to Firefox's "Error console" available in other web browsers? I rely on the error console for identifying JavaScript errors, but I haven't found a straightforward way to view error messages in other browsers like Internet ...

What steps should I take to arrange this information in this particular format?

Exploring nested comments data and structuring it effectively. I am seeking assistance in optimizing a function that can transform an array into a structured format, as depicted below. raw data const data = [ { id: 1, text : "Hell ...

Using Firebase with Angular 4 to fetch data from the database and show it in the browser

Currently diving into Angular 4 and utilizing Firebase database, but feeling a bit lost on how to showcase objects on my application's browser. I'm looking to extract user data and present it beautifully for the end-user. import { Component, OnI ...