例如,我想按属性选择元素ng-controller
(如angularjs中一样)。我有一个div
<div ng-controller="foo1Ctrl"></div>
<div ng-controller="foo2Ctrl"></div>
<div ng-controller="foo3Ctrl"></div>
在scss中,我必须做:
[ng-controller="foo1Ctrl"] {}
[ng-controller="foo2Ctrl"] {}
[ng-controller="foo3Ctrl"] {}
产生我的作用域或嵌套的CSS。我可以在scss中定义一些宏吗?
(在C形式中,可能会沿着这条线出现)
#DEFINE ng(x) [ng-controller="x"]
ng(foo1Ctrl) {}
ng(foo2Ctrl) {}
ng(foo3Ctrl) {}
我只是想知道scss是否确实有这方面的东西。如果没有,那么我将使用原始方法。
该文档显示了您可以在Sass中做的几乎所有事情:http : //sass-lang.com/docs/yardoc/file.SASS_REFERENCE.html#mixin-content
@mixin ng($value) {
[ng-controller="#{$value}"] {
@content;
}
}
@include ng('asdf') {
color: red;
}
输出:
[ng-controller="asdf"] {
color: red;
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句