You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
My site is built with Next.js and Tailwind CSS. I followed the default instructions to install them. Since I wanted to customize the appearance of my links without applying inline classes to each one, I also installed styled-jsx-plugin-postcss so that I could use styled-jsxalready bundled in Next.js.
It worked almost perfectly, but for some reason the dark mode styles applied in the <style jsx> tag are ignored. I'm using the class strategy as documented. How can I make these styles work?
import{useState,useEffect}from"react";exportdefaultfunctionIndexPage(){const[mounted,setMounted]=useState(false);consthandleThemeChange=(newTheme)=>{constbodyClasses=document.body.classList;newTheme==="dark" ? bodyClasses.add("dark") : bodyClasses.remove("dark");localStorage.theme=newTheme;};useEffect(()=>{constdefaultTheme=localStorage.theme||(window.matchMedia("(prefers-color-scheme: dark)").matches
? "dark"
: "light");handleThemeChange(defaultTheme);setMounted(true);},[]);if(!mounted)returnnull;return(<divclassName="dark:bg-black dark:text-white text-xl"><ulclassName="cursor-pointer mb-6"><lionClick={()=>handleThemeChange("dark")}className="block dark:hidden">
Click to activate dark mode
</li><lionClick={()=>handleThemeChange("light")}className="hidden dark:block">
Click to activate light mode
</li></ul><p><ahref="#">This link</a> should be red in dark mode.
</p><stylejsx>{` a { @apply text-green-500 dark:text-red-500; } `}</style></div>);}
The text was updated successfully, but these errors were encountered:
(Cross-posting from StackOverflow)
My site is built with Next.js and Tailwind CSS. I followed the default instructions to install them. Since I wanted to customize the appearance of my links without applying inline classes to each one, I also installed
styled-jsx-plugin-postcss
so that I could usestyled-jsx
already bundled in Next.js.It worked almost perfectly, but for some reason the dark mode styles applied in the
<style jsx>
tag are ignored. I'm using theclass
strategy as documented. How can I make these styles work?Below is a sample code from
index.js
. I also uploaded it to Codesandbox.The text was updated successfully, but these errors were encountered: