Home > Blockchain >  Reference Tailwind Custom colors
Reference Tailwind Custom colors

Time:11-18

In my tailwind config i extend the custom colors as followed:

  theme: {
    extend: {
      colors: {
        // BACKGROUND COLORS
        // Light
        colorBgLight: "#fffef7",
        colorHeaderBgLight: $colorBgLight,
        }
    }
  }

is there a way in the tailwind config I can reference the colorBgLight as a variable for the colorHeaderBgLight just like the example ?

CodePudding user response:

Since the tailwind config file is a js file. You can use any variable within.

So if you set a variable to "#fffef7", you can reference it anywhere within the file.

// tailwind.config.js

let colorBgLight = "#fffef7"

theme: {
  extend: {
    colors: {
      // BACKGROUND COLORS
      // Light
      colorBgLight: colorBgLight,
      colorHeaderBgLight: colorBgLight,
    }
  }
}

CodePudding user response:

Remember that in Javascript you can assign styles to a variable, either in StyleComponents or vanilla Js, for example

let color1 = #f3f3f3

let color2 = #b5b4b9

theme: {
    extends: {
        colors: {
            colorBgLight: color1, //<---variable1
            colorHeaderBgLight: color2,   //<---variable2
        }
    }
}
  • Related