admin管理员组文章数量:1410689
I am developing a product application using Next.js 14 and Shadcn with Tailwind CSS. I want to know the best approach to handling colors in my project. Since this is a product, I want to ensure that colors are managed efficiently. Currently, I am using inline styles for colors, as shown below.
<div className="bg-gray-200 rounded-lg mt-5 text-sm">
Can anyone tell me the standard way to manage colors easily, especially if the product's color scheme changes? I am new to Next.js. In the future, I hope to make changes for dark mode as well.
I am developing a product application using Next.js 14 and Shadcn with Tailwind CSS. I want to know the best approach to handling colors in my project. Since this is a product, I want to ensure that colors are managed efficiently. Currently, I am using inline styles for colors, as shown below.
<div className="bg-gray-200 rounded-lg mt-5 text-sm">
Can anyone tell me the standard way to manage colors easily, especially if the product's color scheme changes? I am new to Next.js. In the future, I hope to make changes for dark mode as well.
Share Improve this question asked Mar 5 at 16:44 StarsStars 234 bronze badges2 Answers
Reset to default 1Not sure what you mean by "best approach to handling colors". If you want to apply custom colors you would extend them through a theme, such as:
// tailwind.config.js
module.exports = {
theme: {
extend: {
colors: {
'custom-color':'#001122',
}
},
},
}
or if you want just set colors do something like:
theme: {
extend: {
colors: {
'primary': '#000',
'secoondary': '#111',
}
},
},
then you'd use the color for example with changing the text color it be
<p class="text-primary">foobar</p>
or like in your example it would be:
<div className="bg-primary rounded-lg mt-5 text-sm">
or
<div className="bg-custom-color rounded-lg mt-5 text-sm">
if you dont want to use the default colors you can override them in the config:
- Customizing your theme
Have you considered theme variables?
https://tailwindcss/docs/theme
You should be able to define your colour scheme as variables and then reference your theme variables. Should you want to change your colour scheme, it should all be centralised in this one place.
In a .css file you can put
@import "tailwindcss";
@theme {
--color-mint-500: oklch(0.72 0.11 178);
}
and then when you want to reference your colours you can use
<div style="background-color: var(--color-mint-500)">
<!-- ... -->
</div>
本文标签: How to handle colors in Nextjs 14 with Tailwind CSSStack Overflow
版权声明:本文标题:How to handle colors in Next.js 14 with Tailwind CSS? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745019996a2638073.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论