1

我只是想在 SASS 中使用“修饰符”和“元素”BEM 语法。

.second-title{
   background-color:green;

  &--touched{
    background-color:black;
  }

  &__left{
   background-color:red;
  }
}

CSS 文件编译正确,但是当我尝试运行“grunt serve”罗盘时会抛出以下错误:

Syntax error: Invalid CSS after \" &-\": expected number or function, was \"-touched{\"\A on line 71 of D:/webdev/angularjs/ang-snapscan/app/styles/mobilestyle.scss";
4

1 回答 1

3

为了以这种方式使用父选择器,您需要使用 Sass 3.3:

http://thesassway.com/news/sass-3-3-released#parent-selector-suffixes

如果您在使用旧版本时遇到问题,可以尝试以下操作:

$module: 'second-title';

.second-title {
   background-color:green;
}

.#{$module}--touched{
  background-color:black;
}

.#{$module}__left{
 background-color:red;
}
于 2014-04-22T12:59:49.253 回答