Issue with styles not being applied when using .modules. In Next.js
P粉504080992
P粉504080992 2023-08-02 20:50:39
0
2
490
<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>
P粉504080992
P粉504080992

reply all(2)
P粉111227898

You can try using styles. title. < h1 className = {styles.heading} >Hello! My style is scss</h1>

P粉787806024

You can use :global to declare that you are using a global class

So main. modules. scss will become

.heading {
    font-size: 4rem;
    color: #000;
}

:global(.dark) .heading {
    color: #fff;
}

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.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template