如果我在SCSS中有这样一个样式定义:
If I have a style definition in SCSS that looks like this:
#someid {
...
.message {
...
&.error {
// overrides of .message class
}
}
}
我在UI中显示了一些消息,可以是普通消息(具有 .message
类),也可以是错误消息(同时具有 .message.error
类)。
现在我有一个显示类似信息的不同元素,既有正常的也有错误的,这就是为什么我想复制错误设置的原因。
如何在不将样式放在单独的类中并扩展/使用它在两个 .error
样式中或使用 mixin 实现相同目的的情况下使用 @extend 指令?我只想重用相同的样式定义。
问题在于当我使用 @extend
时,它会结合所有种类的类继承。
#otherid {
...
.notification {
...
&.error {
// should use the other ".error" style
}
}
}
问题在于编译后的结果具有这种样式定义,其中混合了合并选择器:
#someid .message.error,
#someid #otherid .message.notification.error,
#otherid #someid .message.notification.error
虽然我更愿意只有这两个:
#someid .message.error,
#otherid .notification.error