I don’t know why does my hero section file is inheriting the properties of navbar CSS file. I know that the index.css file passes the properties to entire app, but I don’t use that file instead I make different CSS file for different components. My major problem was with img
tag where I gave different style to hero.css file and navbar.css file but unfortunately hero.css file is using the properties of img
tag of navbar.css. Thus anybody know how to resolve this issue?
This is just to understand the problem rather this can be resolved by giving another name but I want to know why is it inheriting the properties of other CSS file.
2
Answers
In react, if you have a style of the same selector like ‘img’, even in a different file, both sets of rules will apply to all matching elements in the document.
Instead, you can separate the style with css module:
in react, there is only one HTML file, that’s why all css and your react components worked together.
If you wanna unique css files you can use css modules you can find more information here: https://create-react-app.dev/docs/adding-a-css-modules-stylesheet/
If you don’t wanna use css-modules, you can use styled components here is example for