CSS   发布时间:2022-04-17  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了css – Font Face Mixin for Less大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
使用Less我正在定义font-family如下:
@georgia: georgia,times,'times new roman','nimbus roman no9 l',serif;

然后我有更少的mixin:

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

最后我用它这样:

p {
  .font(@georgia,1.0em,1.5)
}

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

@something: 'custom-font',arial,...;

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

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

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

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

或者如果还有一个更好的方法来做到这一点…

谢谢,
米格尔

解决方法

您可以定义自定义混合包含自定义字体,但由于LESS不实现任何控制指令,只能保护mixins(在当前问题的方面无用),因此您无法缩短mixin的字体定义的代码.
.include-custom-font(@family: arial,@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;
    }
}

大佬总结

以上是大佬教程为你收集整理的css – Font Face Mixin for Less全部内容,希望文章能够帮你解决css – Font Face Mixin for Less所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。