#astro tailwind dark not working as expected

12 messages · Page 1 of 1 (latest)

grand knoll
#

Hi all. I've started working with Astro for the first time and can't get Tailwind to generated dark mode CSS like I am expecting it to. Anyone know how I can get it to generate the css when I add new dark mode classes onto elements? I'm using Astroship theme to learn from.
https://github.com/surjithctly/astroship

astro.config.mjs

import tailwind from "@astrojs/tailwind";
import mdx from "@astrojs/mdx";
import sitemap from "@astrojs/sitemap";
import icon from "astro-icon";

// https://astro.build/config
export default defineConfig({
  site: "https://astroship.web3templates.com",
  integrations: [tailwind(), mdx(), sitemap(), icon()],
});

tailwind.config.cjs

const defaultTheme = require("tailwindcss/defaultTheme");
module.exports = {
  content: ["./src/**/*.{astro,html,js,jsx,md,mdx,svelte,ts,tsx,vue}"],
  darkMode: 'class', // Enable dark mode using a class
  theme: {
    extend: {
      fontFamily: {
        sans: [
          "Bricolage Grotesque Variable",
          "Inter Variable",
          "Inter",
          ...defaultTheme.fontFamily.sans,
        ],
      },
    },
  },
  plugins: [require("@tailwindcss/typography")],
};```


\layouts\Layout.astro
```....
....

<!DOCTYPE html>
<html lang="en" class="dark">
....
....```

Then this is where I'm trying to change some link CSS for dark mode. I set some classes in the styles primary variable. They show up in the generated html as expected, but no CSS. 

dark:bg-red dark:text-yellow

\ui\link.astro
```---
...
...
const styles = {
  outline: "bg-white border-2 border-black hover:bg-gray-100 text-black ",
  primary:
    "bg-black text-white hover:bg-gray-800  border-2 border-transparent dark:bg-red dark:text-yellow",
  inverted: "bg-white text-black   border-2 border-transparent",
  muted: "bg-gray-100 hover:bg-gray-200   border-2 border-transparent",
};
...:sob: 
...
...
GitHub

Astroship is a starter template for startups, marketing websites, landing pages & blog. Built with Astro & TailwindCSS - surjithctly/astroship

sharp owl
#

TLDR

Change this darkMode: 'class' to this darkMode: 'selector'

grand knoll
sharp owl
#

I don't unfortunatly, I'm more of a learn by building type of person 😅

icy hazel
# grand knoll Haha. Same.

I did notice that you are using classes like dark:bg-red and dark:text-yellow. Normally, tailwind color classes end in a number [50, 100, 200, 300, 400, 500, 600, 700, 800, 900, 950] like dark:bg-red-500, unless you have created your own custom colors.

grand knoll
#

😨😭 🤦🏻‍♂️

#

Welp. That solved that. 😂

#

Thank you. 😂 Sometimes you just need to step away.

icy hazel
#

Oh don't fret it! I have done the exact same thing way too many times to count. I have found the prettier tailwind plugin a life saver (if you are using it) for this type of thing as it will normally move classes that dont exist/custom to the front of the class list which makes it a bit easier to spot.

sharp owl
#

Nice catch!