css - Less:@font-face 参数混合的第二次调用保留了第一次调用的值

标签 css fonts font-face less

我尝试使用 LESS 包含网络字体。部分完成工作的参数 mixin 如下:

.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; }

当我交换 2 行时:

.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; }

可能是什么原因?我一时不知所措。 非常感谢您。

最佳答案

Based on this current (as of my answer) bug ,我使用了一个人在那里发布的解决方案来修改您的代码。它创建了复制输入 @fontName 的需要,这样您就可以避免将变量传递给 .fontface 调用(现在从 @font 内部调用-face block ),但它确实提供了正确的输出:

.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;
}

关于css - Less:@font-face 参数混合的第二次调用保留了第一次调用的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11605277/

相关文章:

html - 干净的文本渲染

css - 如何在正文中使用一种字体表示正常粗细而另一种字体表示粗体?

css - 如何将 css 应用于 Gtk3-css 中的所有子元素?

css - Firefox Select 下拉列表未继承页面字体

css - 相同的特异性,考虑到布局后,:first-letter always wins?

internet-explorer - CSS3 过渡、jQuery 和 Google 字体的字体渲染不佳的问题

java - 如何获取字体的行高,例如在 JTextArea 中?

ocr - 我可以使用 OCR 检测字体样式(粗体、斜体)吗?

css - "X"的 Unicode 字符取消/关闭?

javascript - JS/DOM 优化 : using :after content styling instead of altering innerHTML