0

我尝试在 LESS 中包含网络字体。部分完成工作的参数混合如下:

.fontface(@fontName, @fontFile) { 
    @font-face { 
        font-family: @fontName;
        src: url("@{fontFile}.eot");    
        src: url("@{fontFile}.eot?#iefix") format('embedded-opentype'),
        url("@{fontFile}.woff") format('woff'),
        url("@{fontFile}.ttf") format('truetype'),
        url("@{fontFile}.svg#DistantGalaxyRegular") format('svg');
        font-weight: normal;
        font-style: normal; } }
.font(@fontsize:10pt, @fontName:"Aierbazzi", @fontFile:"Aierbazzi-fontfacekit/aierbazzi-webfont") { 
        .fontface(@fontName, @fontFile);
font-family:@fontName;
font-size:@fontsize; }

第一次调用它工作正常:

.font1 { .font(24pt, "Black-Rose","Black-Rose-fontfacekit/BLACKR-webfont"); }
.font4 { .font(24pt, "bubblegum-sans","bubblegum-sans-fontfacekit/BubblegumSans-Regular-webfont"); }

结果是:

.font1 { 
    font-family:"Black-Rose";
    font-size:24pt; }
    @font-face { 
        font-family:"Black-Rose";
        src:url("Black-Rose-fontfacekit/BLACKR-webfont.eot");
        src:url("Black-Rose-fontfacekit/BLACKR-webfont.eot?#iefix") format('embedded-opentype'),url("Black-Rose-fontfacekit/BLACKR-webfont.woff") format('woff'),url("Black-Rose-fontfacekit/BLACKR-webfont.ttf") format('truetype'),url("Black-Rose-fontfacekit/BLACKR-webfont.svg#DistantGalaxyRegular") format('svg');
        font-weight:normal;
        font-style:normal; }

.font4 { 
    font-family:"bubblegum-sans";
    font-size:24pt; }
    @font-face { 
        font-family:"Black-Rose";
        src:url("Black-Rose-fontfacekit/BLACKR-webfont.eot");
        src:url("Black-Rose-fontfacekit/BLACKR-webfont.eot?#iefix") format('embedded-opentype'),url("Black-Rose-fontfacekit/BLACKR-webfont.woff") format('woff'),url("Black-Rose-fontfacekit/BLACKR-webfont.ttf") format('truetype'),url("Black-Rose-fontfacekit/BLACKR-webfont.svg#DistantGalaxyRegular") format('svg');
        font-weight:normal;
        font-style:normal; }

当我交换两行时:

.font4 { .font(24pt, "bubblegum-sans","bubblegum-sans-fontfacekit/BubblegumSans-Regular-webfont"); }
.font1 { .font(24pt, "Black-Rose","Black-Rose-fontfacekit/BLACKR-webfont"); }

再次在 CSS 中注册了第一个网络字体:

.font4 { 
    font-family:"bubblegum-sans";
    font-size:24pt; } 
@font-face { 
    font-family:"bubblegum-sans";
    src:url("bubblegum-sans-fontfacekit/BubblegumSans-Regular-webfont.eot");
    src:url("bubblegum-sans-fontfacekit/BubblegumSans-Regular-webfont.eot?#iefix") format('embedded-opentype'),url("bubblegum-sans-fontfacekit/BubblegumSans-Regular-webfont.woff") format('woff'),url("bubblegum-sans-fontfacekit/BubblegumSans-Regular-webfont.ttf") format('truetype'),url("bubblegum-sans-fontfacekit/BubblegumSans-Regular-webfont.svg#DistantGalaxyRegular") format('svg');
    font-weight:normal;
    font-style:normal;}

.font1 { 
    font-family:"Black-Rose";
    font-size:24pt; }
@font-face { 
    font-family:"bubblegum-sans";
    src:url("bubblegum-sans-fontfacekit/BubblegumSans-Regular-webfont.eot");
    src:url("bubblegum-sans-fontfacekit/BubblegumSans-Regular-webfont.eot?#iefix") format('embedded-opentype'),url("bubblegum-sans-fontfacekit/BubblegumSans-Regular-webfont.woff") format('woff'),url("bubblegum-sans-fontfacekit/BubblegumSans-Regular-webfont.ttf") format('truetype'),url("bubblegum-sans-fontfacekit/BubblegumSans-Regular-webfont.svg#DistantGalaxyRegular") format('svg');
    font-weight:normal;
    font-style:normal; }

可能是什么原因?我此刻一无所知。非常感谢您提前。

4

1 回答 1

2

基于这个当前(根据我的回答)的错误,我使用了一个人在那里发布的解决方案来修改您的代码。它需要复制输入,@fontName以避免将变量传递给.fontface调用(现在从@font-face块内部调用),但它确实给出了正确的输出:

较少的

.fontface(@fontName:"Aierbazzi", @fontFile:"Aierbazzi-fontfacekit/aierbazzi-webfont")  {   
    font-family: @fontName;
    src: url("@{fontFile}.eot");    
    src: url("@{fontFile}.eot?#iefix") format('embedded-opentype'),
    url("@{fontFile}.woff") format('woff'),
    url("@{fontFile}.ttf") format('truetype'),
    url("@{fontFile}.svg#DistantGalaxyRegular") format('svg');
    font-weight: normal;
    font-style: normal; 
} 

.font(@fontsize:10pt, @fontName:"Aierbazzi"){
    font-family:@fontName;
    font-size:@fontsize; 
}

.font1 { 
    .font(24pt, "Black-Rose");
    @font-face { 
       .fontface("Black-Rose","Black-Rose-fontfacekit/BLACKR-webfont");
    } 
}

.font4 { 
    .font(24pt, "bubblegum-sans");
    @font-face { 
        .fontface("bubblegum-sans","bubblegum-sans-fontfacekit/BubblegumSans-Regular-webfont");
    } 
}

CSS 输出

.font1 {
  font-family: "Black-Rose";
  font-size: 24pt;
}
@font-face {
  font-family: "Black-Rose";
  src: url("Black-Rose-fontfacekit/BLACKR-webfont.eot");
  src: url("Black-Rose-fontfacekit/BLACKR-webfont.eot?#iefix") format('embedded-opentype'), url("Black-Rose-fontfacekit/BLACKR-webfont.woff") format('woff'), url("Black-Rose-fontfacekit/BLACKR-webfont.ttf") format('truetype'), url("Black-Rose-fontfacekit/BLACKR-webfont.svg#DistantGalaxyRegular") format('svg');
  font-weight: normal;
  font-style: normal;
}
.font4 {
  font-family: "bubblegum-sans";
  font-size: 24pt;
}
@font-face {
  font-family: "bubblegum-sans";
  src: url("bubblegum-sans-fontfacekit/BubblegumSans-Regular-webfont.eot");
  src: url("bubblegum-sans-fontfacekit/BubblegumSans-Regular-webfont.eot?#iefix") format('embedded-opentype'), url("bubblegum-sans-fontfacekit/BubblegumSans-Regular-webfont.woff") format('woff'), url("bubblegum-sans-fontfacekit/BubblegumSans-Regular-webfont.ttf") format('truetype'), url("bubblegum-sans-fontfacekit/BubblegumSans-Regular-webfont.svg#DistantGalaxyRegular") format('svg');
  font-weight: normal;
  font-style: normal;
}
于 2012-07-23T11:33:25.580 回答