Last active
July 18, 2017 14:51
-
-
Save noeldelgado/c94b85bd2fa5a08c86a7 to your computer and use it in GitHub Desktop.
Sass Mixin: font-face
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@mixin font-face($name, $files, $eot: false, $weight: false, $style: false) { | |
$name: quote($name); | |
@font-face { | |
font-family: $name; | |
@if $eot { | |
src: url($eot); | |
$files: join("#{$eot}", $files); | |
} | |
src: add-font-format($files, $name); | |
@if $weight { | |
font-weight: $weight; | |
} | |
@if $style { | |
font-style: $style; | |
} | |
} | |
} | |
@function add-font-format($fonts, $name: '') { | |
$result: (); | |
@each $font in $fonts { | |
$format: ''; | |
$extension: str-slice($font, str-index($font, '.') + 1); | |
@if $extension == "eot" { | |
$font: "#{$extension}?#iefix"; | |
$format: 'embedded-opentype' | |
} @elseif $extension == "ttf" { | |
$format: 'truetype'; | |
} @else { | |
$format: $extension; | |
} | |
@if $extension == "svg" { | |
$font: '#{$font}##{$name}'; | |
} | |
$result: append($result, unquote('url("#{$font}") format("#{$format}")'), comma); | |
} | |
@return $result; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@include font-face('FontName', ( | |
'font.woff', | |
'font.ttf', | |
'font.svg' | |
), 'font.eot', 'bold', 'italic'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@font-face { | |
font-family: "FontName"; | |
src: url("font.eot"); | |
src: url("eot?#iefix") format("embedded-opentype"), url("font.woff") format("woff"), url("font.ttf") format("truetype"), url("font.svg#FontName") format("svg"); | |
font-weight: "bold"; | |
font-style: "italic"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment