Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ReactJS module - Prevent page CSS from applying on React app

Tags:

css

reactjs

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 !

like image 302
Henry Boisgibault Avatar asked Oct 18 '25 04:10

Henry Boisgibault


2 Answers

Try to use these reset classes inside your component

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

like image 94
Hammed Avatar answered Oct 20 '25 06:10

Hammed


Did you try to use CSS-modules ?

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

It might help with your problem.

like image 33
Mathieu Rios Avatar answered Oct 20 '25 06:10

Mathieu Rios



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!