我有以下 CSS:
#extra-info .warning { color: #c33; }
#extra-info .warning, .created-link { font-size: 12px; margin-right: 4px; text-transform: uppercase; }
我想将其转换为 Sass 3.3.10。我尝试了以下方法:
#extra-info .warning {
color: #c33;
&, @at-root .created-link { font-size: 12px; margin-right: 4px; text-transform: uppercase; }
}
但是,这给了我以下错误:
Sass::SyntaxError: Invalid CSS after " &, ": expected "{", was "@at-root .creat..."
我该如何解决这个问题?
我不确定为什么在这种特殊情况下需要使用@at-root,但你可以这样写:
#extra-info .warning{
/* Use @extend directive, because it's designed specifically for this.*/
@extend .created-link;
color: #c33;
@at-root .created-link{
font-size: 12px;
margin-right: 4px;
text-transform: uppercase;
}
}
或者更简单的方法只是将其写在单独的块中:
#extra-info .warning{
@extend .created-link; /*some*/
color: #c33;
}
.created-link{
font-size: 12px;
margin-right: 4px;
text-transform: uppercase;
}
我认为第一个例子更符合“SASS 方式”的概念。 祝你有美好的一天。