1

当我尝试使用 compass 进行编译时,我收到错误消息,指出“混合可能未在控制指令或其他混合中定义”。

以下是我正在使用的代码

@mixin fn-menu {
    $triangle-height: 8px;
    $triangle-width: 16px;

    @mixin menu-marker-inner($pos: top)  {
        $size: 12px;
        $offset-height: $triangle-height;
.......

谷歌搜索时,我发现不支持嵌套 Mixins。但是这个页面http://sass-lang.com/documentation/file.SASS_CHANGELOG.html

**Smaller Improvements**

Mixins and functions may now be defined in a nested context, for example within @media rules. This also allows files containing them to be imported in such contexts.

我正在执行命令

compile sass --sass-dir sass --force

我该如何解决这个问题?

不幸的是,我无法更改编码样式,因为此代码来自产品。

4

1 回答 1

0

@media您可以在规则中甚至在传统的嵌套规则中声明 mixins 和函数,如下所示:

.users{
  @function user-details-width($slots){
    //Some calculation here...
  }

  @mixin user-details{
    //Some syling logic here...
    width: user-details-width(3);
  }

  .details{
    @include user-details; //This is totally OK
  }
}

a{
  @include user-details; //<<<ERROR!!!
}

当你这样做时,你的 mixin 和函数的范围在那个上下文中(并且只在同一级别或以下可见)。

不幸的是,mixin(和函数)不能在其他 mixin 或函数中定义,甚至不能在控制指令(@for, @if, @while@each)中定义。同样的限制也适用于@import 指令。您可以在规则内进行导入,但不能使用“if”指令来限制导入,也不能使用任何其他控制指令(或 mixins 和函数)。

于 2013-11-08T02:57:58.693 回答