I'm experiencing a CSS import issue in my React project. I have a "Home" page that imports Home.css and a "Hero" page that imports Hero.css. Strangely, the styles from Hero.css are being applied to every page in the application without me explicitly declaring it. How can I resolve this issue? Here are the components involved:
App:
import './App.css';
import { BrowserRouter as Router, Route, Routes } from "react-router-dom";
import Home from './pages/home/Home';
import Hero from './pages/hero/Hero';
function App() {
return (
<Router>
<Routes>
<Route path="/" element={<Home />}></Route>
<Route path="/hero" element={<Hero />} ></Route>
</Routes>
</Router>
);
}
export default App;
Hero:
import './Hero.css';
function Hero() {
return <div>
<h1>Hero!</h1>
<button className='glow-on-hover' disabled>test 1</button>
<button className='small-button glow-on-hover'>test 2</button>
<button className='small-button glow-on-hover'>test 3</button>
</div>;
}
export default Hero;
Hero.css:
div {
height: 100%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
justify-items: center;
background-color: #002bff;
}
Home:
import './Home.css';
function Home() {
return <div>
<p>Home!</p>
</div>;
}
export default Home;
Even though the Home.module.css file is empty, the div in the Home component is blue which is only declared in the Hero.module.css. How can I correct this?