shuding / nextra

Simple, powerful and flexible site generation framework with everything you love from Next.js.
https://nextra.site
MIT License
11.74k stars 1.27k forks source link

How do i set a different background color based on theme ? #2122

Open UmbrellaCrow612 opened 1 year ago

UmbrellaCrow612 commented 1 year ago

i have the basic nextra theme, with light and dark mode, i added tailwind css but in the styles i want to add

@tailwind base;
@tailwind components;
@tailwind utilities;

::selection {
  @apply bg-pink-400 dark:bg-cyan-300
}

but the dark dose not work ?

Or how do i just apply slightly different styles depending on the theme ?

UmbrellaCrow612 commented 1 year ago

@shuding

UmbrellaCrow612 commented 1 year ago

i also tried with plain css


[data-theme='dark'] ::selection {
    background-color: pink;
}

[data-theme='light'] ::selection {
    background-color: pink;
}
UmbrellaCrow612 commented 1 year ago

@B2o5T

UmbrellaCrow612 commented 1 year ago

Found a solution i think

Tailwind config

/** @type {import('tailwindcss').Config} */
module.exports = {
  prefix: "nx-",
  darkMode: ["class", 'html[class~="dark"]'],
  content: [
    "./components/**/*.{ts,tsx}",
    "./pages/**/*.{md,mdx}",
    "./theme.config.tsx",
  ],
};

then _app.mdx

import '../global.css'

export default function App({ Component, pageProps }) {
  return (
    <div className="selection:nx-bg-pink-400 dark:selection:nx-bg-slate-100">
      <Component {...pageProps} />
    </div>
  )
}

seems to work