我在课堂上使用奇数子伪选择器时遇到一些困难。odd:bg-blue-200 内联使用时效果很好。但我想提取这种样式,以便在给定类 .tr 时,我的所有表行都具有这种样式。我一直在查看文档,但解决方案一直困扰着我。我希望这里有人可以提供帮助。
到目前为止,我已经尝试过:
.tr:odd {
@apply bg-blue-200;
}Run Code Online (Sandbox Code Playgroud)
和
@variants odd {
.tr {
@apply bg-blue-200;
}
}Run Code Online (Sandbox Code Playgroud)
在 tailwind.config.js 中,我添加了 backgroundColor 变体:
variants: {
'backgroundColor': ['responsive', 'odd', 'hover']
},Run Code Online (Sandbox Code Playgroud)
只需一个普通的 css 规则就可以与 tailwind 的 @apply 结合使用。 (不需要为此进行配置更改。)
.tr:nth-child(odd) {
@apply bg-blue-200;
}
Run Code Online (Sandbox Code Playgroud)