6

我想对我的背景图像应用线性渐变。在 tailwind 配置文件上,我写了一个自定义规则,如下所示:

 theme: {
    extend: {
      backgroundImage: (theme) => ({
        'hero-pattern': "url('../src/images/icon-bg.jpg')",
  
      }),
    },
  },

有用。但是当我尝试应用线性渐变时,它并没有起作用。

对于应用线性渐变,我尝试过的是:

 theme: {
    extend: {
      backgroundImage: (theme) => ({
        
         'hero-pattern':
          "linear-gradient(to right bottom, rgba('#7ed56f',0.8), rgba('#28b485',0.8)), url('../src/images/icon-bg.jpg')",
      }),
    },
  },

但它没有用。

4

2 回答 2

9

不要使用函数。只是尝试作为一个实用程序

theme: {
    extend: {
      backgroundImage: {
         'hero-pattern': "linear-gradient(to right bottom, rgba('#7ed56f',0.8), rgba('#28b485',0.8)), url('../src/images/icon-bg.jpg')",
      },
    },
  },

这是一个工作示例https://play.tai​​lwindcss.com/uHp6pKIKEc

于 2021-05-01T11:20:57.077 回答
4

问题是您给出了十六进制颜色代码,rgba这就是不应用颜色的原因。

你必须给予rgba color code而不是hex color code

注意:只有 scss 支持 rgba 内的十六进制颜色代码

于 2021-05-03T14:58:46.620 回答