Font Face Mixin for Less

Mig*_*ura 10 css less

使用Less我按如下方式定义字体系列:

@georgia: georgia, times, 'times new roman', 'nimbus roman no9 l', serif; 
Run Code Online (Sandbox Code Playgroud)

然后我有更少的mixin:

.font(@family: arial, @size: 1.0em, @lineheight: 1.0, @weight: normal, @style: normal, @variant: normal) {
  font: @style @variant @weight @size~"/"@lineheight @family;
} // font
Run Code Online (Sandbox Code Playgroud)

最后我像这样使用它:

p {
  .font(@georgia, 1.0em, 1.5)
}
Run Code Online (Sandbox Code Playgroud)

但我还想用自定义字体定义字体系列:

@something: 'custom-font', arial, ...;
Run Code Online (Sandbox Code Playgroud)

但首先我需要注册自定义字体:

@font-face {
  font-family: 'custom-font';
src:url('fonts/custom-font.eot');
src:url('fonts/custom-font.eot?#iefix') format('embedded-opentype'),
    url('fonts/custom-font.woff') format('woff'),
    url('fonts/custom-font.ttf') format('truetype'),
    url('fonts/custom-font.svg#icon') format('svg');
font-weight: normal;
font-style: normal;
}
Run Code Online (Sandbox Code Playgroud)

是否可以创建一个LESS mixin,@font-face因此我可以传递字体名称和路径并注册字体而不重复所有这些代码?

我不知道如何将其与我的字体混合...

或者,如果有更好的方法来做到这一点......

谢谢你,米格尔

Laj*_*ros 17

您可以定义自定义mixin以包含自定义字体,但由于LESS没有实现任何控制指令,只有mixins的保护(在当前问题的方面无用),因此您无法缩短mixin的字体定义代码.

.include-custom-font(@family: arial, @weight: normal, @style: normal){
    @font-face{
        font-family: @family;
        src:url('fonts/@{family}.eot');
        src:url('fonts/@{family}.eot?#iefix') format('embedded-opentype'),
            url('fonts/@{family}.woff') format('woff'),
            url('fonts/@{family}.ttf') format('truetype'),
            url('fonts/@{family}.svg#icon') format('svg');
        font-weight: @weight;
        font-style: @style;
    }
}
Run Code Online (Sandbox Code Playgroud)