How can I import stylesheet locally for single view.
I am having two views /home and /blog and the following directory of files:
src
│
└───components
│
└───Home
│ Home.js
│ Home.css
└───Blog
Blog.js
Blog.css
I have a seperate css file home.css for home view only but that style is getting applied to blog view also.
I want the home.css file to work only with the home.js view.
Home.css
.text1 {
font-size: 1em !important;
font-family: "Noto Sans", sans-serif !important;
color: red;
}
Home.js
import React, { Component } from "react";
import "./home.css";
class Home extends Component {
render() {
return (
<div className="text1" style={{ overflow: "Hidden" }}>
<h1>This must be red.</h1>
<a href="/blog">Go to Blog</a>
</div>
);
}
}
export default Home;
Blog.js
import React, { Component } from "react";
import "./blog.css"; //I didn't Import Home.css here and blog.css is and empty css file.
class Blog extends Component {
render() {
return (
<div className="text1" style={{ overflow: "Hidden" }}>
<h1>This must be black.</h1>
<a href="/">Go to Home</a>
</div>
);
}
}
export default Blog;
Here is the React App: