Not all CSS custom properties are functioning properly, despite being included in the HTML code and being visible in the inspector tool

I've been experimenting with implementing different themes on my website. I modified my main stylesheet to include variables and created three additional "theme" stylesheets that define these variables at the :root level. The HTML file then connects to two stylesheets: the main one and a chosen theme, which can be switched by clicking a button that changes the href attribute. Strangely, only some of the variables are functioning as expected.

/* dark.css (a theme stylesheet with custom properties) */
/* Only --background works */
:root {
    --background: #000000;

    --seperator: rgba(1,1,1,0.12);
    --text: #FFFFFF;

    --block-border: #404040;
    --block-shadow: #000000;
    --block-background: #151017;
}

/* All properties work except for --comment */
code {
    --keyword: #F72057;
    --type: #FF9519;
    --call: #FF5700;
    --property: #FF5700;
    --number: #F72057;
    --string: #F72057;
    --comment: #FFFFFF;
    --dot-access: #FF5700;
    --preprocessing: #646485;
}

Upon inspecting, all seems fine. Inheritance is correct, and clicking on the variable in use reveals the desired color.

Here are some examples of how the variables are utilized:

/* styles.css (main stylesheet) */
body {
    ...
    background: var(--background);
    color: var(--text);
}

pre code .comment {
    color: var(--comment);
    opacity: 0.4;
}

Different Approaches Tried

I attempted various strategies, but encountered the same issue (only certain variables working).

  1. Modifying the variables directly with JavaScript instead of linking to another stylesheet
  2. Utilizing three distinct main stylesheets rather than multiple theme stylesheets
  3. Changing a custom attribute within the HTML tag and defining all variables like [theme="dark"] {...} in a primary stylesheet

Answer №1

After receiving feedback from both @Pushkin and @Temany Afif, I noticed unusual characters scattered throughout my code. Thankfully, a simple find and replace operation across the entire project resolved the issue.

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

Tips on formatting vueJS HTML5 with tidy without compromising its structure or content

Using the tidy tool on this VueJS code causes it to completely break: Here is the initial VueJS HTML code: $ cat sample_vue.html ... <tbody> <tr v-for="task in tasks"> <td><strong>{{task.title}}< ...

Using Angular: How to reference the same ng-template with a component in a single HTML file without making a copy

Currently, I am facing a challenge while developing a web application using Angular. My task involves creating a search form with multiple fields as a component. Below is the code snippet for this component: <ng-template #filter> <app-articles-f ...

Tips for correctly sending the response code from a Node.js API

I have a straightforward node-based API that is responsible for parsing JSON data, saving it into a Postgres database, and sending the correct response code (e.g., HTTP 201). Here is an excerpt of my code: router.route('/customer') .post(fu ...

I'm encountering an issue with the dropify plugin where the data-allowed-file-

While using the dropify library to style file upload elements in my form, I ran into an issue with the data-allowed-file-extensions parameter not working as expected. Despite specifying allowed file extensions like "png jpg jpeg", the validation for input ...

Instructions for generating multiple components in React when an array is not at your disposal

In the process of developing a Tic-Tac-Toe game, I am in need of creating 9 empty squares. Currently, I have a ul element and 9 li elements representing each square in the game. The issue is that there is no array available for looping through and generati ...

Trouble with NodeJS async/await - navigating through function arguments

Currently, I am attempting to perform web scraping using a particular library while implementing Node's async/await method in my code. Within the function named 'sayhi', I have created a variable 'page' and encountered an issue wh ...

How to align pagination in the center using Bootstrap

This code is for pagination features: <div class="pagination"> <ul> <li><a href="?p=0" data-original-title="" title="">1</a></li> <li><a href="?p=1" data-original-title="" title="">2< ...

difficulty encountered when passing parameters in functions such as setInterval

Hi everyone, I need some help with my code. Feel free to check it out here Currently, I'm working on implementing multiple circular progress bars that can function dynamically. The goal is to be able to add additional progressCircle_# objects with di ...

Tips on stopping slideToggle from opening and closing when clicked for the first time

When using the slideToggle function, I'm encountering an issue where the content div briefly shows on the first click but then immediately slides closed. Subsequent clicks work as expected and slide open correctly. This is the Jquery script I have be ...

Exploring the realm of JavaScript and finding the perfect spot

Looking to learn more about locating elements and using javascript effectively. For example, when a user clicks on an element, I want to display a menu right below it. I also need to consider scenarios where the element is located at the edge of the page ...

Screen rendering can be a challenging task

As I dive into learning how to use THREE.js for creating browser games, I've encountered a roadblock. Every time I attempt to import a model using the code, the screen just renders black. Surprisingly, I've been smoothly coding and running it in ...

What methods can be used to block direct attribute updates in a JS/TS class?

class Creature { secretProperty modifySecretProperty(value) { this.secretProperty = value } } new Creature().modifySecretProperty('hidden way') //success new Creature().secretProperty = 'not permitted' // failure To r ...

Tips for retrieving the identifier of a row in a mui datagrid when an onClick event occurs

I'm attempting to integrate a material-ui datagrid with a sql database for the purpose of enabling edits to be made via a form rather than editing individual rows and cells one by one. My goal is to pass the row's id as a parameter to a function ...

JavaScript: what is the method to add a paragraph when the condition is not met?

I am currently working on a project that involves checking if a student is actively engaged in an online journal. This is done by tracking the student's progress using a unique userId. If the student's userId is not found in the JSON data returne ...

Jest is simulating a third-party library, yet it is persistently attempting to reach

Here's a function I have: export type SendMessageParameters = { chatInstance?: ChatSession, // ... other parameters ... }; const sendMessageFunction = async ({ chatInstance, // ... other parameters ... }: SendMessageParameters): Promise<vo ...

Having trouble with changing the state within an AngularJS (Ionic Framework) controller?

My goal is to switch views within the Search controller after receiving search results from the server through $http. However, my current approach doesn't seem to be working as intended. I also need to pass the response to the new view for displaying ...

Troubleshooting: HTML Image Map not showing tooltips

Everything seems to be working fine on the webpage, except for the tooltips on certain areas of the image. Only the first area title displays a tooltip when hovering over any part of the image. Here is the HTML code I am using: <html> <map nam ...

Within a div element, there are links that I would like to hover over to emphasize the text

Hey there, I'm looking to make the text change color when you hover over the entire div. Currently, only the background changes color, but I want the text to as well. Thank you for your assistance! .shadow-box .service-box {text-align:center;borde ...

Setting a radio button as default based on a variable value can be accomplished by following a few

I am working with 2 radio buttons and I need to dynamically check one based on a variable value. <input type="radio" name="team" id="team_7" value="7"> <input type="radio" name="team" id="team_8" value="8"> The variable number is set dependin ...

Modifying text appearance and design in material-ui release 0.15.4

I'm quite new to CSS and front-end web development, and I'm struggling with setting the style of a button on my page. I want to change the text color and possibly adjust the primary color of my theme from cyan to blue. I know that material-ui has ...