Failed to set CSS variable in Electron

My current dilemma involves CSS variables not being properly set. I am utilizing electron and attempting to establish them in this manner:

 for (let Button of ThemeButtons){
    Button.addEventListener("click", e =>{
      let Color = Button.style.backgroundColor;
      let root = document.documentElement

      console.log(Color)
      root.style.setProperty('--CurrentA', Color);
      root.style.setProperty('--CurrentB', Color);
      root.style.setProperty('--CurrentC', Color);
    });
  }

I have defined my variables like this:

:root {
  --red:#923333;
  --orange:#d68a00;
  --green: #0d840d;
  --blue: #1c4a90;
  --purple: #6a1d8a;
  --dark: #313131;
  --gray: rgb(68, 68, 68);
  --light: #b7b7b7;

  --CurrentC: rgb(85, 85, 85);
  --currentA: rgb(68, 68, 68);
  --currentB: rgb(53, 53, 53);
}

While the color prints accurately, the variable remains unset. I have explored 'BlinkFeatures' and configured them accordingly, yet the issue persists. Any insights into what might be causing this?

Answer №1

It appears that the issue here lies within the realm of CSS specificity. When using :root, it targets the root of the document tree (HTML tag), similar to document.documentElement. However, :root holds a higher level of specificity, as explained further here.

To address this issue effectively, consider adjusting the variable overrides to apply to elements like the body tag, or make modifications from :root {} to html {}

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

The state initialization process is beginning with an [object Object] being passed into the setState function

Within the async function provided below, I am invoking stationData to verify that an array of objects is being passed into bartData (which currently consists of an empty array). Upon exploration, I have observed a response containing the anticipated array ...

What is the best way to load information from the initial array onto a randomly chosen card?

Is there a way to populate data from the first array on a randomly selected card? I am trying to create a random card in Angular, where when I click on the first card, it will display the first value from the array and automatically fill the other cards w ...

The problem with JQuery ajax arises when attempting to send a file input value

I am facing an issue when trying to send a file value to PHP using the ajax code below. The file gets uploaded successfully and stored in the database, but the problem arises when I get redirected. // form data submission $('#myForm').submit(fun ...

Angular 13 does not currently have support for the experimental syntax 'importMeta' activated

Since upgrading to angular 13, I've encountered an issue while attempting to create a worker in the following manner: new Worker(new URL('../path/to/worker', import.meta.url), {type: 'module'}) This code works as expected with "ng ...

Flexbox search bar positioned above a set of flexbox buttons

In an attempt to replicate Google's search bar, the following code has been developed: <head> <title>Search</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <link r ...

Display a collection of objects using Jade / Pug syntax

Struggling to find resources on Pug / Jade templating, turning to this platform for help. I've been diving into documentation on iterations along with consulting this helpful link. Working with Node.js, Express, and pug for a school project - a mock ...

HttpInterceptor is failing to intercept certain requests

After upgrading to the new version of Angular 8, I encountered an issue where the authorization token is not being sent in the request header for certain requests. Despite checking everything, the problem persists. When inspecting the console, I noticed th ...

Three divs arranged side by side with responsive design for mobile viewing

This code generates 3 divs for display. However, I am looking to optimize them for mobile devices. What steps can I take to accomplish this? Currently, the divs are oriented to the left and are not visible on a mobile device. I would like them to display ...

Looking to update the URL from another component?

My current project is using Angular 6 and I am working on creating a list of buttons on the left panel such as "Ice cream", "Pop corns", and more. The goal is for users to click on these buttons which will then change the URL of the add button located in t ...

Discover and select an element based on its partial `onclick` attribute value

Can an element be clicked through selenium based on a partial value of an onclick attribute? There are several input elements on the page, and I am interested in selecting one with a specific string. Examples would include: <input name="booksubmit" t ...

Issue with the MUI Autocomplete display in my form

Recently, I started using Material UI and Tailwind CSS for my project. However, I encountered an issue with the Autocomplete component where the input overlaps with the following DatePicker when there is multiple data in the Autocomplete. I have attached a ...

The use of async components in Vue.js with named imports

I understand how to dynamically load components asynchronously in Vue. For example, instead of importing MyComponent directly: import MyComponent from '@/components/MyComponent' export default { components: { MyComponent } } We can use ...

Does Javacc have a capability to generate JavaScript code as an output?

Is there a parser generator available that can take a Javacc grammar file (.jj) and produce a JavaScript parser instead of Java? If not, what would be involved in converting the .jj file into a format that ANTLR can interpret (since it has the capability ...

Creating Responsive Social Icons using HTML and CSS

Currently working on my portfolio website, but encountered an error. Can someone assist me in making my social icons responsive? I need the icons to be responsive and aligned horizontally for the mobile version. Here is a visual of the issue with the desk ...

Tips for displaying the number of selected values in a select box label (e.g. Choose an Option)

I am currently using the jQuery multiselect API in my application to allow users to select multiple values. However, I am facing an issue where I need to fetch all the selected values when a button next to the multiselect box is clicked. Unfortunately, I h ...

Ensuring security against cross site scripting attacks on window.location.href

Currently, I'm utilizing window.location.href to redirect the page to an external URL: <Route exact path={rootUrl} component={() => { window.location.href =`https://${window.location.hostname}/www/testurl?google=true`; return null; }} /> How ...

Issue with transparent background appearing unexpectedly during fade in/out effect in Internet Explorer 8 while using jQuery galleria

For my girlfriend's birthday, I am working on a surprise website for her. However, I have encountered a minor visual problem in Internet Explorer 8 (and possibly 7) with the fade in/out effect when switching images in an iframe gallery. While other br ...

Enhancing performance with multiple spotlights in Three.js

Currently working on a racing game using three.js and encountering a specific issue... There are 2 cars in the game, each requiring a minimum of 4 spotlights for rear and front car lights... In addition, there is a need for lights on the road... Here is ...

Error due to callback function in FullCalendar selection in Javascript

Currently, I am in the process of integrating fullcalendar into a project that I have been working on. Unfortunately, I have encountered some errors with the select: callback function when attempting to submit an ajax request. Here is what my select: callb ...

Does JavaScript Map Access Use Indexing for Efficient map.get Retrieval?

Is the map.get method in V8 optimized by indexing JavaScript-Map-object's keys, or does it loop through the entire map to find a key match? I'm curious about the efficiency of map.get with larger mappings containing 500,000+ key/value pairs. I h ...