Issue with styles not being applied when using .modules. In Next.js
P粉504080992
2023-08-02 20:50:39
<p>I launched a Next.js 13 application,<br /><br />I have a main.modules.css file</p><p><code>< ;/code></p>
<pre class="brush:php;toolbar:false;">.heading {
font-size: 4rem;
color: #000;
}
.dark .heading {
color: #fff;
}</pre>
<p>I use it to style components like this</p>
<pre class="brush:php;toolbar:false;">import styles from "@/styles/main.module.scss";
export default function Home() {
return (
<>
<Header />
<h1 className={styles["heading"]}>Hi! I was styled by scss</h1>
</>
);
}</pre>
<p>From. The styles for the heading class are applied correctly, but from. The attribute dark .heading does not have. <br /><br />My theme provider does add one to the HTML element. dark category. <br /><br />I used a normal one. scss file and apply a class like this</p><p><br /></p>
<pre class="brush:php;toolbar:false;"><h1 className="heading">Hi! I was styled by scss</h1></pre>
<p>Then it worked fine</p>
You can try using styles. title. < h1 className = {styles.heading} >Hello! My style is scss</h1>
You can use :global to declare that you are using a global class
So main. modules. scss will become
Why is this happening?
Why is this happening?
The scope of CSS modules is the components they use.
This means by default. The dark selector will be compiled and will not reference the global one. dark category.