1

When I add new HTML code to my React app , the CSS styles from the App.css file aren't applying anymore , until I retype Import './App.css'" in the head. Any solution please.

0

2 Answers 2

2

Problem solved , it was about bootstrap .

Import bootstrap/dist/css/bootstrap.min.css before App.css .

I was doing the opposite .

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

1 Comment

Dear friend , You never mentioned you were using any third party CSS library in your Questions :) Anyways, happy coding friend. So, what was happening in your case was, App.css styles were getting override from classes in Bootstrap :) cool. As per your question asked @Rachid, I have answered it earlier. If it has helped you in any way or form, do please accept it as it takes encourages me to help more and more developers :) Thank You
1

All our components in React act like modules and have their data (variables, functions) private to them. To access code or styles from other files we need import from other modules.

Our App.js is also one such component. Until you do import './App.css', the CSS will not be applied to App.js.

7 Comments

So I just have to delete and retype import './App.css' everytime I edit the HTML code in App.js ? doesn't seem like a sweet solution
Why would you be deleting it? You leave the import statement in your top level file
thats the problem in the first place . I am leaving the import and the CSS won't applied until I retype it. @Grant
@RachidL'harime There could be a few reasons why that is happening, we would need to know more details about your individual case, i.e share some code with us, it could even be a build issue with your current tools but we won't be able to diagnose it any further without more information
@Rachid: Bro, There are few ways to include CSS in our React. 1 is keep everything in index.css file, second is using Same named CSS file as your component and then importing in that component. Which you are trying to do.
|

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.