Implement a CSS rule when the menu is in an open state

Is there a way to modify the color of the hamburger icon when the menu is open?

I'm unsure on how to approach this. My assumption is that I need to check if the 'active' class is present and then apply specific CSS code.

You can view the site here:

<body>

<div class="page-transition">
  <div class="layer"></div> 
</div>

<nav class="site-navigation">
  <div class="layer"></div>
  <div class="inner">
    <ul data-splitting>
      <li><a href="/">Maison</a> <small>Retour au début</small></li>
      <li><a href="/">Le Tournoi</a> <small>A propos de l'événement</small></li>
      <li><a href="studio.html">Les Joueurs</a> <small>All About Us</small> </li>
      <li><a href="showcases.html">Le Site</a> <small>Our all projects</small> </li>
      <li><a href="blog.html">Media</a> <small>Recent posts</small> </li>
      <li><a href="contact.html">Galerie</a> <small>Say hello</small> </li>
      <li><a href="contact.html">Pro AM</a> <small>Say hello</small> </li>
      <li><a href="contact.html">Partenaires</a> <small>Say hello</small> </li>
       <li><a href="/contact">Pro AM</a> <small>Contact</small> </li>
    </ul>
  </div>
</nav>

<div class="social-media">
  <div class="layer"> </div>
  <div class="inner">
    <h5>Social Share </h5>
    <ul>
      <li><a href="index.html#"><i class="fab fa-facebook-f"></i></a></li>
      <li><a href="index.html#"><i class="fab fa-twitter"></i></a></li>
      <li><a href="index.html#"><i class="fab fa-linkedin-in"></i></a></li>
      <li><a href="index.html#"><i class="fab fa-google-plus-g"></i></a></li>
      <li><a href="index.html#"><i class="fab fa-youtube"></i></a></li>
    </ul>
  </div>
</div>

<div class="all-cases">
  <div class="layer"> </div>
  <div class="inner">
    <ul>
      <li><a href="index.html#">Darkness</a></li>
      <li><a href="index.html#">Goddes</a></li>
      <li><a href="index.html#">Employee</a></li>
      <li><a href="index.html#">Berry</a></li>
      <li><a href="index.html#">Roosters</a></li>
      <li><a href="index.html#">Primero</a></li>
    </ul>
  </div>
</div>

<main>
  <aside class="left-side">
    <div class="logo"> <a href="index.html"><img src="/themes/paris-legends-championship/assets/images/branding/paris-legends-icon.png" alt="Image"></a> </div>
    <div class="hamburger" id="hamburger">
     ...
    </div>
    <div class="follow-us"> FOLLOW US </div>
    
  </aside>

  <div class="all-cases-link"> <span>Leaderboard</span> <b><i class="fa fa-table" aria-hidden="true"></i></b> </div>

Current CSS:

.hamburger__line-in::after, .hamburger__line-in::before {
    width: 60px;
    height: 2px;
    content: '';
    display: block;
    position: absolute;
    top: 0;
    background-color: #fff;
}

Modified CSS:

.hamburger__line-in::after, .hamburger__line-in::before {
    width: 60px;
    height: 2px;
    content: '';
    display: block;
    position: absolute;
    top: 0;
    background-color: #C1A473;
}

If anyone has a solution, it would be greatly appreciated.

Answer №1

To modify the CSS properties, you have options such as using jQuery or pure JS. Alternatively, you can style child elements based on a toggling class with pure CSS, handling states like hover if needed:

.hamburger.is-opened-navi .hamburger__line.hamburger__line--cross01 *::after,
.hamburger.is-opened-navi .hamburger__line.hamburger__line--cross02 *::after {
    background-color: #122e1A;
}

Testing reveals that using ::before and ::after works better:

.hamburger.is-opened-navi .hamburger__line.hamburger__line--cross01 *::before,
.hamburger.is-opened-navi .hamburger__line.hamburger__line--cross02 *::before,
.hamburger.is-opened-navi .hamburger__line.hamburger__line--cross01 *::after,
.hamburger.is-opened-navi .hamburger__line.hamburger__line--cross02 *::after {
    background-color: #122e1A;
}

Edit: Opting for a dark green color instead of solid red might complement the site design more.

As for the "follow-us" link, which may be overlooked especially with Ad Block Plus, using jQuery for dynamically changing its style could be more suitable since it lacks ancestor classes that change when the menu opens. You can create a CSS class for its active state:

.follow-us.active {
    color: #C1A473;
}

Add a simple click listener to switch its active class (place it before the closing </body> tag inside a <script></script>):

$('.hamburger').click(function() {
  $('.follow-us').toggleClass('active');  
});

Answer №2

CSS is not about executing commands, but rather about setting up rules that determine how styles are applied to different elements based on their selectors. It seems like there may be an issue with the way your .active class is being applied - it appears to be assigned to a container separate from the one containing the hamburger icon. To address this, consider applying the class to a parent element that encompasses both the current location and the hamburger icon. This way, you can write a single rule that affects both elements when the .active class is added. Another option is to assign the .active class to multiple elements, including the parent of the hamburger icon along with its current placement.

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 is the best way to achieve a horizontally compact layout in Bootstrap by centering the content?

I am looking to center my content on the page and maintain a close proximity between items within a div. However, with Bootstrap 5, when I resize the page wider, additional space is added which pushes the items apart. Is there a way to keep them compacted ...

Using jQuery and regex to only allow alphanumeric characters, excluding symbols and spaces

Seeking advice, I am using a jquery function called alphanumers var alphanumers = /^[a-zA-Z0-9- ]*$/; which currently does not allow all symbols. However, I now wish to disallow the space character as well. Any suggestions? ...

Is it possible to alter the JSON file being loaded in AngularJS by passing a variable?

I am in need of loading the content from either food1.json or food2.json, and I am attempting to achieve this within the html template: <body ng-controller="MainCtrl" ng-init="init('food1')"> Subsequently, in the JavaScript code: $scop ...

Using JQuery to obtain an array of the widths of the td elements in a specific row

I am attempting to retrieve an array containing the width of all td's in a row. To start, I fetch the array of all the td's: datas = $('.totals').prev().find("tr").last().find("td"); Next, in order to confirm that I am using the $.map ...

I'm looking for a way to set up a PropType that accepts a boolean value, but also allows for

Currently, my code includes a Modal component with a prop called disableEscapeKeyDown. The PropType defines it as boolean | null, but when trying to use it in the ModalWindow function, I receive an error stating Type 'boolean | null' is not assig ...

Best practice for showcasing the output of an array in Javascript

My variables are defined in an array like this: const nbActions = 13; const sdgValues = ['1', '2', '5', '6', '3', '0', '2', '0', '0', '6', '0', & ...

Tips for utilizing an observable in Angular without subscribing to it

I am currently working on an Angular 8 application that involves making API calls. Here is an example: getDossierEntry(patientUUID: string, type: String = ''): Observable<DossierEntry[]> { const entryType = type === '' ? ' ...

CSS: Only one out of three <div>'s has the styles applied in JSFiddle

When working on my project, I encountered an issue while trying to add CSS styles to three <div> structures with unique IDs. Strangely, making small changes to unrelated CSS caused elements to go from being stylized to losing their style. If you com ...

Loading dynamic images in HTML using Javascript and Django templates

Attempting to load a specific image using javascript within a django template has presented challenges due to the formatting of django tags. The standard django static asset source in an img tag looks like this: {% load static %} <img src="{% static & ...

Utilize the ng-controller directive with unique aliases across various sections of HTML code

I'm facing an issue with my ng-controllers when multiple controllers are used on the same page. For instance, I have one controller in the page header, another in a different section of the same page, and one in the content of the page. However, all o ...

Next.js React struggles to receive click events within a customized hook in order to modify the state of the parent component

Struggling with React (Next.js) here. I'm attempting to have a click event in a custom hook modify the state of a parent component, which should then reveal a list beneath the data table. Unfortunately, the API call and data variable are located withi ...

What methods can be used to prevent FireFox from continuously loading with a long-polling request?

Currently, I am implementing a long-polling request using the code snippet below (which is comparable to getJSON)... $.jsonp({ "url": url, "data": { "settings", settings }, "success": function(userProfile) { // handling user profile in ...

Struggling with filtering an array fetched from an API using VueJS

Currently, I am working on a Nativescript-Vue app and facing some challenges that I need help with. The Scenario I have data coming in from an API. Here is the structure of the data I receive: { "count": 9, "results": [ { "id": 1, "c ...

What is the best way to fetch HTML content using JavaScript?

I needed to incorporate JavaScript for fetching HTML code. I structured the HTML code in the following manner; <html> <div id="tesingCode"> <h1>Title</h1> <p>testOfCodetestOfCodetestOfCodetestOfCode</p> </div ...

Obtaining the accurate offsetTop and offsetLeft values for an element following a CSS3 rotation

Is there a method to accurately determine the offsetTop and offsetLeft values of an element post-transform rotation? Are there any lesser-known element properties that could be helpful in this scenario? Attached is an image that can provide further clari ...

The issue of req.file being undefined when using Multer in Node.js with Express Router

I have been working on incorporating File Upload capability utilizing multer and Express Router. I set up an endpoint /batch_upload using router.use in the following manner: api.js router.use( "/batch_upload", upload.single("emp_csv_data"), userCo ...

Struggling to implement a Rock Paper Scissors game using HTML, CSS Bootstrap4, and JavaScript, specifically facing challenges in getting the function to select a new image

Recently, in my coding class, we were tasked with creating a program that would display images of dice and generate random numbers when the refresh button was clicked. To practice using querySelector and setAttribute, I decided to expand on the lesson by i ...

An error occurs when using e.slice function

I am facing an issue with my kendoDropDownList that uses kendo UI and jQuery. I cannot figure out why this error is occurring. $("#drpState").kendoDropDownList({ optionLabel: "States...", delay: 10, ...

"Uploading" a picture using jQuery

I have been using this particular code snippet to display messages. setTimeout(function(){ o.html(o.html() + "Username:<br>" + msg[r] + "<br><hr>") }, 7000); It's effective in posting messages from an array and adding some st ...

Single array returned by observable

Issue: I am looking for a way to consolidate the multiple arrays returned individually into a single array. Solution: fetchAllRiders() { var distanceObs = Observable.create(observer => { this.http.get(this.API + '/driver/all').map(res = ...