【问题标题】:How to get colour values from tailwind config file如何从顺风配置文件中获取颜色值
【发布时间】:2021-01-02 15:10:52
【问题描述】:

我想从配置文件中访问“强调”颜色的值,以便将其分配给新颜色。我试过danger: theme('colors.accent'),但我收到了这个错误> theme is not defined。我想避免再次硬编码十六进制颜色代码。有没有办法轻松做到这一点?

tailwind.config.js

colors: {

accent: '#57A0D7',
accentlight: '#88BCE2',
accentdark: '#4B8CBD',
accentdarker: '#4682B0',

danger: theme(colors.accent),

【问题讨论】:

    标签: javascript css tailwind-css


    【解决方案1】:

    当然。只需设置您希望出现在module.exports 之外的多个位置的值,您可以在任何地方将其用作变量,因为配置文件只是一个 js 文件。

    const accent = '#57A0D7';
    
    module.exports = {
      theme: {
       colors: {
        accent,
        accentlight: '#88BCE2',
        accentdark: '#4B8CBD',
        accentdarker: '#4682B0',
        danger: accent
       }
      }
     }
    

    【讨论】:

      【解决方案2】:

      尝试使用函数

      colors: {
      
      accent: '#57A0D7',
      accentlight: '#88BCE2',
      accentdark: '#4B8CBD',
      accentdarker: '#4682B0',
      
      danger: theme => theme('colors.accent'),
      

      【讨论】:

        猜你喜欢
        • 2020-07-21
        • 2013-05-16
        • 2023-03-14
        • 2011-04-01
        • 2021-09-08
        • 2019-11-06
        • 1970-01-01
        • 2011-10-10
        • 2021-07-20
        相关资源
        最近更新 更多