简体   繁体   English

如何使用 base Tailwind CSS colors 和 daisyUI 主题

[英]How to use base Tailwind CSS colors along with daisyUI theme

I'm using Tailwind CSS along with daisyUI for a NextJS project.我将 Tailwind CSS 与 daisyUI 一起用于 NextJS 项目。 I have my tailwind.config.js file set up as:我将tailwind.config.js文件设置为:

/** @type {import('tailwindcss').Config} */
/* eslint-env node */
module.exports = {
    content: [
        './pages/**/*.{js,ts,jsx,tsx}',
        './components/**/*.{js,ts,jsx,tsx}',
        'node_modules/daisyui/dist/**/*.js',
        'node_modules/react-daisyui/dist/**/*.js',
    ],
    theme: {
        extend: {},
        fontFamily: {
            sans: ['Roboto', 'sans-serif'],
        },
    },
    daisyui: {
        themes: [
            {
                mytheme: {
                    primary: '#8855B4',
                    secondary: '#00C9AF',
                    accent: '#f3d0f5',
                    neutral: '#373f4a',
                    'base-100': '#FFFFFF',
                    info: '#3ABFF8',
                    success: '#36D399',
                    warning: '#FBBD23',
                    error: '#F87272',
                },
            },
        ],
    },
    plugins: [require('daisyui')],
}

When I try to use a color defined within my daisyUI theme, it works fine:当我尝试使用在我的 daisyUI 主题中定义的颜色时,它工作正常:

<h1 className="text-3xl font-bold text-accent">Your Trips</h1>

在此处输入图像描述

But when I use a color defined in base tailwind, it does not work.但是当我使用在 base tailwind 中定义的颜色时,它不起作用。

<h1 className="text-3xl font-bold text-red-400">Your Trips</h1>

在此处输入图像描述

As you can see, the text is black instead of red-400.如您所见,文本是黑色而不是红色 400。

It seems like daisyUI is overriding my access to Tailwind colors?似乎 daisyUI 正在覆盖我对 Tailwind colors 的访问权限? How can I use the base tailwind colors along with a daisyUI theme?如何将基本顺风 colors 与 daisyUI 主题一起使用?

I believe you may have overridden the default theme with the daisyui theme as opposed to extending the default theme.我相信您可能已经用 daisyui 主题覆盖了默认主题,而不是扩展默认主题。

You should be able to correct this by moving your theme components to the extend section in your tailwind.config.js.您应该能够通过将主题组件移动到 tailwind.config.js 中的扩展部分来更正此问题。

Extending the default theme 扩展默认主题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM