在 tailwind css 中动态设置悬停值
我想根据顺风的类别名称设置不同的文本颜色悬停。 我设置了一个配置,每个颜色代码都引用这样的类别:
tailwind.config.js
theme: {
extend: {
}
},
colors: {
transparent: 'transparent',
current: 'currentColor',
"animation": "#A72608",
"decor": "#E0AFA0",
"illustrations": "#32936F",
"developpement-visuel": "#C2FCF7",
"realisations": "#FEEA00",
"croquis": "#9F6BA0",
"white": "#FFFFFF",
},
并在我的组件中像这样使用它:
sidebar.js
<nav>
<ul>
{categories.map((category) => {
return (
<li key={category.id} className="mb-4">
<Link href={`/category/${category.attributes.slug}`}>
<a className={`hover:text-${category.attributes.slug} uppercase font-light text-sm`}
>{category.attributes.name}</a>
</Link>
</li>
)
})}
</ul>
</nav>
但事实证明它不起作用。当我查看开发工具 ${category.attributes.slug} 时,它实际上被替换为类别的名称和我在配置中给出的名称
I want to set a different text color hover depending on categories name with tailwind.
I set a config with each color code refering to a category like this :
tailwind.config.js
theme: {
extend: {
}
},
colors: {
transparent: 'transparent',
current: 'currentColor',
"animation": "#A72608",
"decor": "#E0AFA0",
"illustrations": "#32936F",
"developpement-visuel": "#C2FCF7",
"realisations": "#FEEA00",
"croquis": "#9F6BA0",
"white": "#FFFFFF",
},
and using it like this in my component :
sidebar.js
<nav>
<ul>
{categories.map((category) => {
return (
<li key={category.id} className="mb-4">
<Link href={`/category/${category.attributes.slug}`}>
<a className={`hover:text-${category.attributes.slug} uppercase font-light text-sm`}
>{category.attributes.name}</a>
</Link>
</li>
)
})}
</ul>
</nav>
but it turns out that it doesn't work. When I look at the devtools ${category.attributes.slug} is effectively replace be the name of the category and the name I gave in my config
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以尝试在
tailwind.config.js
中配置文本颜色的悬停效果吗Can you try to config hover effect for text color in
tailwind.config.js