2016-12-05 24 views
1

比方说,我有以下的mixin:如何在保留原始输出的同时重新定义现有的混音?

@mixin foo { 
    color: red; 
} 

这混入在一个库中导入,所以我不想去触摸的源代码。不过我想扩展mixin的功能,并添加我自己的样式。

所以我需要一种方法来创建具有相同名称的新混合料搅拌,同时保留原有的输出,但允许我补充新的输出,是这样的:

@mixin foo { 
    color: blue; 
} 

@mixin foo { 
    @include foo; // this is the original 
    font-size: 14px; 
} 

当然上面也不会做什么我想要,但是我能做些什么吗?

回答

1

我一直在玩弄与此似乎工作上来:

@mixin foo() { 
    color: red; 
} 

%foo { 
    @include foo; 
} 

@mixin foo() { 
    @extend %foo; 
    font-size: 22px; 
} 

.foo { 
    @include foo; 
} 
+0

非常聪明的解决方案。总的来说,我会建议创建一个新的mixin,但我也可以考虑一些需要覆盖的情况(使用良好的文档不会混淆未来的开发人员)。 – alexbea

0

您可以扩展/使用@content;,而您在默认情况下其内部线路一个混合的变化代码块。

@mixin foo(){ 
    background:green; 
    border:solid 5px black; 
    @content; 
} 
div{ 
    width:200px; 
    height:100px; 
    &.one{ 
    +foo(){ 
     border:0; 
    } 
    } 
} 

https://jsfiddle.net/Thielicious/hhb09b61/

相关问题