有没有办法在父选择器的同一行使用 & ?
Is there a way to use the & on the same line as the parent selector?
我想做的是将相同的样式应用到按钮的默认状态和它的聚焦状态。所以像这样,但实际样式不止一行:
.my-button {
color: red;
&:focus: {
color: red;
}
}
为了避免重复样式,我希望我可以这样写:
.my-button, &:focus {
color: red;
}
当然,&
不是这样的。有什么办法吗?
我知道我可以写.my-button, .my-button:focus { ... }
。我只是想了解 Sass.
是否可行
您可以单独使用父选择器,&, &:focus
:
.my-button {
&, &:focus {
color: red;
}
}
我想做的是将相同的样式应用到按钮的默认状态和它的聚焦状态。所以像这样,但实际样式不止一行:
.my-button {
color: red;
&:focus: {
color: red;
}
}
为了避免重复样式,我希望我可以这样写:
.my-button, &:focus {
color: red;
}
当然,&
不是这样的。有什么办法吗?
我知道我可以写.my-button, .my-button:focus { ... }
。我只是想了解 Sass.
您可以单独使用父选择器,&, &:focus
:
.my-button {
&, &:focus {
color: red;
}
}