Skip to content

Instantly share code, notes, and snippets.

@noeldelgado
Last active July 18, 2017 14:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save noeldelgado/c94b85bd2fa5a08c86a7 to your computer and use it in GitHub Desktop.
Save noeldelgado/c94b85bd2fa5a08c86a7 to your computer and use it in GitHub Desktop.
Sass Mixin: font-face
@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;
}
@include font-face('FontName', (
'font.woff',
'font.ttf',
'font.svg'
), 'font.eot', 'bold', 'italic');
@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