Unresolved styles in React component linked to styles.css file

As I dive into creating a registration page in ReactJS, I encounter a frustrating issue with my styles not applying correctly from the styles.css file.

Let's take a look at my RegisterPage.jsx component:

export default function RegisterPage() {
  return (
    <>
        <div className="row g-0">
            <div className="col-7 background">Background</div>
            <div className="col-5 registerForm">RegisterForm</div>
        </div>
    </>
  )
}

And here are the styles defined in my styles.css:

body{
    background: #cccaaa;
}

.background{
    background: "#8d45b7";
}

.registerForm{
    background: "#fff";
    height: 100vh;
}

I've made sure to include my styles.css in my index.html file:

<!-- My CSS -->
    <link type="text/css" href="./src/styles.css" rel="stylesheet">

However, only the body style seems to be applied correctly, as seen here:

body{
    background: #cccaaa;
}

The classes-based styles like .background and .registerForm don't work unless I apply them directly within the component, like this for the RegisterForm:

export default function RegisterPage() {
  return (
    <>
        <div className="row g-0">
            <div className="col-7">Background</div>
            <div
                className="col-5"
                style={{ 
                    background: "#fff",
                    height: "100vh",
                }}>
                RegisterForm
            </div>
        </div>
    </>
  )
}

Ultimately, I aim to define all my styles in styles.css rather than in each individual component. What could be causing this hiccup?

Answer №1

Transform it into the following:

.bg {
    background-color: #4167ad;
}

.signupForm {
    background: #ffffff;
    height: 100vh;
}

Answer №2

I managed to identify the error, I mistakenly wrote:

background: "#8d45b7";

When it should have been:

background: #8d45b7;

Silly mistake :)

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

Having issues with Promise.resolve() not functioning as expected in a Jasmine test

I am currently working on setting up a test that involves promises. Below is the code snippet for reference: var promise; beforeEach(inject(function ($q) { promise = $q.resolve(); })); it('should resolve', function (done) { promise.the ...

Differences between JSX.Element, ReactNode, and ReactElement: When should each be utilized?

Currently in the process of transitioning a React application to TypeScript. Everything seems to be going smoothly, however I've encountered an issue with the return types of my render functions, specifically within my functional components. In the p ...

"Encountering problem with Angular HTTP services: the requested URL is not

Attempting to send data to API servers is resulting in a 404 error. Testing it on Postman shows that everything works fine. JSONP is being used for posting data due to cross-domain issues. The console displays the following: GET http://myapi.com/registrat ...

Arranging JSON data based on related properties in JavaScript

I have a JSON order with multiple products associated by vendorId, and I'm seeking to group them into separate arrays rather than having all of them listed together. How can I accomplish this? Here is my code: let order = { "product ...

Eliminating render-blocking CSS in PageSpeed - one stylesheet at a time

Currently, I am testing the best optimization practices for front-end development. As part of this process, I have utilized gulp and npm to merge and minify my CSS and JS files into a single all.min.css and js.min.css file. Upon analyzing my website using ...

Struggling to showcase API data on React interface

I am working on fetching data from a private API and displaying it on a web page. My frontend is built using React JS, while my backend uses Node with Express and Axios. Everything seems to be working fine until the point where I need to display the fetche ...

Empty space under the banner in Wordpress theme Avada

I can't seem to locate the CSS class for a blank space that appears below the header on one of my pages. This space is situated between the header and "SERVICIOS 24 HORAS". Any ideas on how I can remove this mysterious gap? My website is built wit ...

Error: PHP is showing an undefined index error when trying to decode JSON, even though the value

I am feeling quite puzzled. I transferred a key value pair object from jQuery to PHP and successfully alerted it back out. However, when I visit the PHP page, it indicates that the data is either null or an undefined index. Here is my jQuery code: $(&ap ...

Tips on showcasing lengthy string content from JSON in a structured list format using react with typescript

Is there a way to display long string data from a JSON file in a list format when the description string is too lengthy? How can I split or format the description using React and TypeScript? The JSON data I have is as follows: "options": [ ...

Get rid of the background shade in the area separating the menu items within a CSS menu

Is there a way to add some spacing between the menu items without affecting the background color applied to the anchor tags? I currently use a right margin of 13px for the spacing, but it also applies the background color, which is not the desired outcome ...

Retrieve a value using the jQuery each() method

Hello, I am a beginner in JavaScript and I need help with extracting values from JSON and adding them to an array. My goal is to be able to parse this array using another function later on. However, I'm struggling with returning the array after adding ...

Press the Text and Alter Text with React

I'm having an issue with the onClick event using React hooks. My goal is to have the text change to a different one when the user clicks, and then revert back to the original text on another click. For example, clicking "Change First" should switch it ...

Efficiently configuring an Array with Wordpress REST API in JavaScript

Here's a two-part question: 1) My goal is to fetch elements from WordPress' REST API and store them in an array called map_locations. The first part of the function involving $.ajax works as intended, showing data when I log it. However, the lat ...

React component state not being updated as expected

I've been developing an app for managing income and expenses, which allows users to input data and select the type of income or expense from a dropdown list. The issue I'm facing is that my Total Income (Total expense will be added once this pro ...

JS Tips for using the .push() function with Multidimensional Arrays in JavaScript

After coming across this code example online, I decided to give it a try. The code snippet involved using the JavaScript array push method to add new elements to an inner sub-array, which was exactly what I needed to achieve! The code successfully demons ...

Resource Jump.js could not be loaded

Although I am still new to NPM, I have mostly built websites without using it. Recently, I decided to implement smooth scroll using Jump.js. Initially, everything seemed to work well when I used the live server extension in VScode. However, once I uploade ...

Modify every audio mixer for Windows

Currently working on developing software for Windows using typescript. Looking to modify the audio being played on Windows by utilizing the mixer for individual applications similar to the built-in Windows audio mixer. Came across a plugin called win-audi ...

Create custom layouts in NextJS based on the browser URL detection

Trying to implement an optional layout in NextJS, I encountered a problem. I have been trying to find a method to check the browser URL and serve content based on that URL. However, this approach led to server content and browser content becoming different ...

The model name should not be overridden if it is already being used in different fields

I have a model that I am binding on two sides. The first side is inside an html p tag, and the second side is a textarea. When I make changes to the textarea, the content inside the p tag also changes. How can I ensure that only the content in the textar ...

Saving several inputs with incremented values

I'm facing an issue with saving data from multiple input fields in a for loop: <input type="number" name="device_id_1"> <input type="number" name="device_id_2"> ... <input type="number" name="name_1"> <input type="number" name="n ...