9

I am trying to style a React Component. To achieve this, I am importing a CSS file and using className such as indicated in the React Documentation.

I have added a css-loader + style-loader to my webpack.config.js file as described below:

const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
  mode: "development",
  entry: "../src/index.js",
  output: {
    path: path.resolve(__dirname, "../dist"),
    filename: "bundle.js",
  },
  devtool: 'inline-source-map',
  devServer: {
    contentBase: '../dist',
    port: 8080
  },
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /(node_modules|bower_components)/,
        use: {
          loader: 'babel-loader',
          options: {
            presets: ['@babel/preset-env', '@babel/preset-react']
          }
        }
      },
      {
        test: /\.css$/,
        use: [ 'style-loader', 'css-loader' ]
      }
    ]
  },
  plugins: [new HtmlWebpackPlugin(
    {template: '../src/index.html'}
  )]
}

Here is my App.js React Component:

import React, {Component} from "react"
import "./App.css"

const App = () => (
  <div className="hello-world">Hello World</div>
)

export default App

And my App.css file:

.hello-world{
  color: "#272C35"
}

My CSS content is correctly loaded since the property + value appear in the development tool. But for some reason, the value is marked as incorrect as shown below:

Capture of navigator inspect mode with incorrect css value

2 Answers 2

26

You don’t need quotes around the color hexadecimal value in the CSS file.

Sign up to request clarification or add additional context in comments.

1 Comment

Ok i was used to write css in javascript objects so i forgot a little about css -_- this does the trick.. Thanks a lot
0

The same happened here, because I was writing CSS under MUI (Material UI) on directly on the components, and forgot about the unnecessary quotes.

4 Comments

Welcome to Stack Overflow! This appears to be an attempt to comment on another answer and say that it worked for you. However, Stack Overflow does restrict new users from posting comments on others' posts. This reduces spam and also allows you to demonstrate that you understand how to use the site features before you gain new abilities. When you gain a bit more rep, you'll be able to upvote questions and answers (which is the SO way of saying, "Thanks! This worked for me!") as well as comment on others' posts.
We do hope you'll stick around and gain reputation by posting good questions and answers, or by providing edits that improve existing questions and answers.
This is not an answer. Please use comments when askin clarification or when adding details to the questions.
This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From Review

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.