Font Face Mixin for Less

前端 未结 7 541
暖寄归人
暖寄归人 2021-01-11 23:20

Using Less I am defining font-families as follows:

@georgia: georgia, times, \'times new roman\', \'nimbus roman no9 l\', serif; 

Then I ha

相关标签:
7条回答
  • 2021-01-11 23:43

    I like to structure my fonts on folders, like this:

    /fonts/OpenSans-Bold/OpenSans-Bold.eot
    /fonts/OpenSans-Bold/OpenSans-Bold.svg
    /fonts/OpenSans-Bold/OpenSans-Bold.ttf
    /fonts/OpenSans-Bold/OpenSans-Bold.woff
    

    And i use this LESS MIXIN for font-face:

    .font-face(@fontName: sans-serif; @fontWeight: normal; @fontStyle: normal) {
        @font-face {
            font-family: @fontName;
            src: url('@{pTheme}/fonts/@{fontName}/@{fontName}.eot');
            src: url('@{pTheme}/fonts/@{fontName}/@{fontName}.eot?#iefix') format('embedded-opentype'),
                 url('@{pTheme}/fonts/@{fontName}/@{fontName}.woff') format('woff'),
                 url('@{pTheme}/fonts/@{fontName}/@{fontName}.ttf') format('truetype'),
                 url('@{pTheme}/fonts/@{fontName}/@{fontName}.svg#@{fontName}') format('svg');
            font-weight: @fontWeight;
            font-style: @fontStyle;
        }
    }
    

    Where:

    @pTheme: "../../themes/[THEME NAME]";
    

    Mixin call example:

    .font-face('OpenSans-Bold');
    

    I've made the @pTheme variable so i can use it also on background images, like this:

    background: url("@{pTheme}/images/logo.png") no-repeat;
    
    0 讨论(0)
提交回复
热议问题