TailwindCSS背景-图像在黑暗模式下不工作

9njqaruj  于 2023-06-25  发布在  其他
关注(0)|答案(2)|浏览(178)

我的Tailwind类定义如下:

<section class="dark:bg-gray-900 bg-hero-image bg-fixed">

因此,在浅色版本中显示背景图像,而在深色版本中仅显示gray-900作为背景颜色。
图像在tailwind.config.js中定义如下:

theme: {
    extend: {
      backgroundImage: {
        'hero-image': "url('/header.jpg')"
      },

但这只是不工作,仍然显示在黑暗模式的图像。

mwecs4sa

mwecs4sa1#

您必须将backgroundImage添加到tailwind.config.js中的variants

module.exports = {
  variants: {
    extend: {
      backgroundImage: ["dark"],
    },
  },

另外您必须添加dark:bg-none,以便将background-image设置为none

<section class="dark:bg-gray-900 dark:bg-none bg-hero-image bg-fixed">

这对于invert和许多其他类也是必要的。检查文档中的相应部分,无论默认情况下是否包含变体。
默认情况下,仅为反转实用程序生成响应变量。https://v2.tailwindcss.com/docs/invert#variants

aij0ehis

aij0ehis2#

<div className='my-20 p-10 bg-gradient-to-r from-[#D1FFD0] to-[#BBE7FF] dark:from-[#263238] dark:to-[#263238]  dark:text-white rounded-[20px]'>
      <div>
        <p className='text-center text-[16px] md:text-[20px] font-semibold'>
          If you're still unsure about whether software development is the right
          fit for you, it may be comforting to know that the employment rate for
          software engineers stands at an impressive 93%*.
        </p>
      </div>
      <div className='my-5'>
        <p className='text-center text-[16px] md:text-[18px] font-normal'>
          "Secure your spot now by reserving a seat and begin your journey as a
          software developer!"
        </p>
      </div>
      <div className='mt-6 flex items-center justify-center'>
        <button className='px-8 py-4 bg-[#00A3FF] rounded-[30px] text-white hover:transition hover:duration-5000 hover:ease-in-out hover:bg-gradient-to-r hover:from-blue-400 hover:to-purple-500'>
          BOOK A FREE DEMO
        </button>
      </div>
    </div>

这适用于灯光模式下的正常渐变:bg-gradient-to-r from-[#D1FFD0] to-[#BBE7FF]
dark:from-[#263238] dark:to-[#263238] dark:text-white用于暗模式。
示例:Dark Mode示例:Light Mode

相关问题