i am creating a react component Comp1
and i am importing a css file inside it like this->
import "./style.css";
inside style.css
i am doing something like this->
@import "https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css";
but the problem is, this is applying css to all components in react and ruining everything. i want to apply only inside the particular component Comp1
and specifically in this tag->
<div className="comp1">
</div>
please guide me on this. how do i do that? let me know if u need any more info.
2
Answers
If you use Create React App, you can use CSS modules for this.
like @tymzap mentioned, you can use css modules.
In JS, you need to rename your filename.css to filename.module.css
and you need to import that css file to your react component
In TS, you need to create a type declaration file named declarations.d.ts
in that file you need to define css or scss files as modules.
hope it will help.