有可能的。
你的两个mixin是这样的:
.font-data-icon(@font-family){
[data-icon]:before {
font-family: @font-family;
content: attr(data-icon);
speak: none;
font-weight: normal;
font-variant: normal;
text-transform: none;
line-height: 1;
-webkit-font-smoothing: antialiased;
}
}
.icon-class(@font-family){
[class*="icon-"] {
font-family: @font-family;
speak: none;
font-style: normal;
font-weight: normal;
font-variant: normal;
text-transform: none;
line-height: 1;
-webkit-font-smoothing: antialiased;
}
}
然后你可以调用 mixins,传递所需的参数:
.font-data-icon('Icons_Font');
.icon-class('Icons_Font');
或者两者都只有一个mixin,如果两者的属性保持不变:
.font-mixin(@font-family){
font-family: @font-family;
speak: none;
font-style: normal;
font-weight: normal;
font-variant: normal;
text-transform: none;
line-height: 1;
-webkit-font-smoothing: antialiased;
}
并在两条规则中像这样调用它两次:
[data-icon]:before {
.font-mixin('Icons_Font');
}
[class*="icon-"] {
.font-mixin('Icons_Font');
}
两种情况下的 CSS 输出都是:
[data-icon]:before {
font-family: 'Icons_Font';
content: attr(data-icon);
speak: none;
font-weight: normal;
font-variant: normal;
text-transform: none;
line-height: 1;
-webkit-font-smoothing: antialiased;
}
[class*="icon-"] {
font-family: 'Icons_Font';
speak: none;
font-style: normal;
font-weight: normal;
font-variant: normal;
text-transform: none;
line-height: 1;
-webkit-font-smoothing: antialiased;
}