Font Face Mixin for Less

前端 未结 7 589
暖寄归人
暖寄归人 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:34

    U can try this mixin for font-face (font Proxima Nova as expl):

    .fontFace(@fontWidth) {
        @fontName: "Proxima Nova @{fontWidth}";
        @fileName: "../fonts/ProximaNova-@{fontWidth}";
        @font-face {        
            font-family: '@{fontName}';
            font-weight: 400;
            font-style: normal;
            src: url('@{fileName}.eot');
            src: url('@{fileName}.eot?#iefix') format('embedded-opentype'),
                 url('@{fileName}.woff') format('woff'),
                 url('@{fileName}.ttf') format('truetype'),
                 url('@{fileName}.svg#@{fontName}') format('svg');
        }
    }
    
    .fontFace('Regular');
    .fontFace('RegularIt');
    .fontFace('Bold');
    
    @fontName: Proxima Nova;
    @font:          "@{fontName} Regular";
    @font_italic:   "@{fontName} RegularIt";
    @font_bold:     "@{fontName} Bold";
    
    h2 {
        font: 400 50px @font_bold;  
    }
    

    And, as the same thing, this staff at SASS/SCSS:

    @mixin font ($weight) {
        @font-face {
            $fontName: 'Proxima Nova ' + $weight;
            $fileName: '../fonts/ProximaNova-' + $weight;
    
            font-family: $fontName;
            font-weight: 300;
            font-style: normal;
            src: url($fileName + '.eot ');
            src: url($fileName + '.eot?#iefix') format('embedded-opentype'),
               url($fileName + '.woff2') format('woff'),
               url($fileName + '.ttf') format('truetype'),
               url($fileName + '.svg##' + $fontName) format('svg');
        }
    }
    @include font(regular);
    @include font(bold);
    @include font(light);
    
    $fontName: 'Proxima Nova ';
    $font: $fontName + regular, "Helvetica Neue", sans-serif;
    $font_bold: $fontName + bold;
    $font_light: $fontName + light;
    
    h2 {
        font: 300 15px $font_bold;
    }
    

提交回复
热议问题