搜索过但未找到答案..
我有一个元素,由外部平台生成,具有以下类:p-button和button。
现在SCSS如下:
.p-button {
&.button {
margin: 10px;
}
}
但我希望使用mixin includes进行重构(这是一个大型项目,除了使用mixins没有其他更好的方法来改善代码)。mixin接受给定的选择器并在其前添加"."。我无法更改mixin,因为它被许多其他团队使用,所以我无法将&符号与选择器一起传递。我尝试过以下方法:
.p-button {
& {
@include button-appearance("button") {
margin: 10px;
}
}
}
但这不起作用(会在它之间放置一个空格)。你无法这样做:
.p-button {
&@include button-appearance("button") {
margin: 10px;
}
}
有人有线索吗?
编辑:这里是混合器
@mixin button-appearance(
$appearance-class,
$show,
$background-color,
$background-image,
$background-position) {
$sel: $button-selector;
@if $appearance-class {
$sel: $sel + '.' + $appearance-class;
}
#{$sel} {
@include normalized-background-image($background-image);
@include show($show);
background-color: $background-color;
background-position: $background-position;
}
@content;
}
编辑2:这里是$button-selector(我无法在平台上进行编辑,但也许可以在我的项目中覆盖它?)
$button-class: 'p-button';
$button-selector: '.#{$button-class}';
.button
类的样式,用于.p-button
选择器? - pjones235$button-selector
的值吗? - muecas