You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Tailwind v4(Vite + React)自定义颜色失效问题求助

Tailwind v4(Vite + React)自定义颜色失效问题求助

各位好,我现在在Vite + React的项目里用Tailwind v4,遇到了自定义颜色完全失效的问题,折腾了好久都没搞定,来求助大家!

我先是用了Tailwind v3的配置格式来定义自定义颜色,配置文件是这样的:

// tailwind.config.js
import { defineConfig } from 'tailwindcss'

export default defineConfig({
  content: [ 
    "./index.html", 
    "./src/**/*.{js,ts,jsx,tsx}" 
  ],
  theme: {
    extend: {
      colors: {
        azulote: '#064d9c',
        amarillote: '#fbce10',
        azulito: '#6490c0',
        amarillito: '#e2deb7',
      }
    }
  },
  plugins: [],
});

但不管怎么试,这些自定义颜色在项目里就是用不了,完全没效果。

后来我又换成了Tailwind v4的推荐格式,写在了样式文件里:

@import 'tailwindcss'
@theme {
  --color-azulote: #064d9c;
  --color-amarillote: #fbce10;
  --color-azulito: #6490c0;
  --color-amarillito: #e2deb7;
}

结果更糟,用了这个格式之后,网站直接完全识别不了Tailwind了,所有原本的Tailwind样式都没了,整个页面的视觉风格全乱了。

我项目里已经配置了PostCSS,但实在搞不懂问题出在哪,有没有大佬能帮忙分析下?

内容来源于stack exchange

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.07 12:14:31