4

I have a React app that can be included in a page.

My problem is that I don't want to have conflicts between the page's CSS and my React app's CSS.

To prevent my CSS from spilling to the page content, I can simply use a namespace on all my CSS classes, such as "react_app".

But how to prevent external CSS from being used by my react app ? For example the page defines :

body {
    font-size: 1em;
    line-height: 1.8;
}

How can I make sure that my react components will not pick it up ?

A solution would be to define "line-height" for all my classes to override this definition, but I don't want to do that because it is not possible to cover all properties and it would take space.

Thanks for your help !

2

2 Answers 2

2

Try to use these reset classes inside your component

https://meyerweb.com/eric/tools/css/reset/

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

2 Comments

Interesting tool, however it doesn't cover all cases. Do you know a more generic version to block external CSS ?
1

Did you try to use CSS-modules ?

https://github.com/gajus/react-css-modules

It might help with your problem.

Comments

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.