如何为 tailwind-css 添加新颜色并保留原来的颜色?
How to add new colors to tailwind-css and keep the original ones?
如何为默认方案添加颜色?这是我的 tailwindcss 文件。
const { colors: defaultColors } = require('tailwindcss/defaultTheme')
module.exports = {
"theme": {
"colors": defaultColors + {
"custom-yellow": {
"500": "#EDAE0A",
}
},
},
};
您可以简单地使用“Array/Object 传播运算符”(...) 将它们连接起来,然后将它们全部收集到一个 colors
变量中。
// tailwind.config.js
const { colors: defaultColors } = require('tailwindcss/defaultTheme')
const colors = {
...defaultColors,
...{
"custom-yellow": {
"500": "#EDAE0A",
},
},
}
module.exports = {
"theme": {
"colors": colors,
}
};
将您的自定义颜色值添加到 tailwind.config.js
中的主题 > 扩展 > 颜色部分
//tailwind.config.js
module.exports = {
theme: {
extend: {
colors: {
'custom-yellow':'#BAA333',
}
},
},
}
Try this code then restart localhost
`module.exports = {
purge: ['./src/**/*.{js,jsx,ts,tsx}', './public/index.html'],
darkMode: false, // or 'media' or 'class'
theme: {
extend:
{colors:
{
pinkSoft: '#EDC7B7',
wheat: '#EEE2DC',
gray: '#BAB2B5',
blue: '#BADFE7',
blue2: '#697184',
pink: '#D8CFD0',
bg: '#B1A6A4',
bgDark: '#413F3D',
},},
},
variants: {
extend: {},
},
plugins: [],
}`
您还可以从顺风扩展调色板中选择颜色。
https://tailwindcss.com/docs/customizing-colors#color-palette-reference
// tailwind.config.js
const colors = require('tailwindcss/colors')
module.exports = {
theme: {
extend: {
colors: {
orange: colors.orange,
},
}
}
}
如何为默认方案添加颜色?这是我的 tailwindcss 文件。
const { colors: defaultColors } = require('tailwindcss/defaultTheme')
module.exports = {
"theme": {
"colors": defaultColors + {
"custom-yellow": {
"500": "#EDAE0A",
}
},
},
};
您可以简单地使用“Array/Object 传播运算符”(...) 将它们连接起来,然后将它们全部收集到一个 colors
变量中。
// tailwind.config.js
const { colors: defaultColors } = require('tailwindcss/defaultTheme')
const colors = {
...defaultColors,
...{
"custom-yellow": {
"500": "#EDAE0A",
},
},
}
module.exports = {
"theme": {
"colors": colors,
}
};
将您的自定义颜色值添加到 tailwind.config.js
中的主题 > 扩展 > 颜色部分//tailwind.config.js
module.exports = {
theme: {
extend: {
colors: {
'custom-yellow':'#BAA333',
}
},
},
}
Try this code then restart localhost
`module.exports = {
purge: ['./src/**/*.{js,jsx,ts,tsx}', './public/index.html'],
darkMode: false, // or 'media' or 'class'
theme: {
extend:
{colors:
{
pinkSoft: '#EDC7B7',
wheat: '#EEE2DC',
gray: '#BAB2B5',
blue: '#BADFE7',
blue2: '#697184',
pink: '#D8CFD0',
bg: '#B1A6A4',
bgDark: '#413F3D',
},},
},
variants: {
extend: {},
},
plugins: [],
}`
您还可以从顺风扩展调色板中选择颜色。 https://tailwindcss.com/docs/customizing-colors#color-palette-reference
// tailwind.config.js
const colors = require('tailwindcss/colors')
module.exports = {
theme: {
extend: {
colors: {
orange: colors.orange,
},
}
}
}