我有一个自定义的类设置,我正在尝试添加变体,但行为似乎与经典CSS没有什么不同。
@layer components {
@variants hover, focus {
.btn-primary {
background-color:blue;
}
}
.btn-primary{
@apply bg-primary rounded-sm border-4 border-primary rounded-sm text-white text-base py-2 px-4 capitalize transition-all;
}
}如果变体是在.btn-primary之后,那么它应用蓝色背景就像什么都不是一样。悬停或专注于工作。
下面是我根据我看到的其他帖子在我的顺风配置中添加的内容:
variants: {
extend: {
backgroundColor: ['hover'],
}
}发布于 2021-02-21 08:27:33
您可以直接在.btn-primary定义中使用hover:和focus:前缀。
.btn-primary {
@apply bg-primary hover:bg-blue-700 focus:bg-blue-700 rounded-sm border-4 text-white text-base py-2 px-4 capitalize transition-all;
}您也不需要将hover和focus变量添加到配置中的backgroundColor属性,因为它在缺省情况下已经启用。
https://stackoverflow.com/questions/66297167
复制相似问题