1

I dont know why this setup is not displaying the styles.

App.js component:

import React from 'react';
import './App.css';

class App extends React.Component {
    constructor () {
        super();
    }

    render () {
        return (
            <div className="App">
                <h1>Test Header</h1>
            </div>
        );
    }
}

export default App;

App.css:

h1 {
    color: "red";
}

Directory Structure:

src/

  • App.css

  • App.js

The h1 element is not red. Why

2
  • Dear @Jim, Do you use CRA for this sample code? Commented Feb 13, 2020 at 23:52
  • yes, I believe it was used Commented Feb 13, 2020 at 23:53

2 Answers 2

4

It's simple you used the string "red" instead of red. Try this instead:

h1 {
  color: red;
}

That should work now.

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

2 Comments

Exactly right, you act like a tiger. nice, I leave an upvote for your high intelligence
No worries Jim! Happens to us all from time to time.
-1

It's because you have red in quotes. Take off the quotes. Also, you don't need className="App". You actually don't have a css class called "App"., just an h1 {...;}.

This should work:

h1 {
    color: red;
}
<div>
    <h1>Test Header</h1>
</div>

2 Comments

yes it did save. and removing className="App" did not fix
Dear @Jim, Actually, using a useless class name doesn't cause to this issue. I think this issue is more than it appears. I guess it's from its configs.

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.