Skip to content

Instantly share code, notes, and snippets.

@davidpollet
Last active October 12, 2017 11:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidpollet/56ed99e019cc20bfc991f3b58445b55a to your computer and use it in GitHub Desktop.
Save davidpollet/56ed99e019cc20bfc991f3b58445b55a to your computer and use it in GitHub Desktop.
Sass Mixin font-face generator
// Built from https://css-tricks.com/snippets/css/using-font-face/
// Codepen demo : https://codepen.io/davidpollet/pen/ORyYap
@mixin font-face( $font-name, $font-path, // path + file name. Ex : path/to/font/filename
$font-weight: 400, $font-style: normal, $support-required: 'modern') {
@font-face {
font-family: $font-name;
font-style : $font-style;
font-weight: $font-weight;
@if $support-required=='oldie' {
src: url('#{$font-path}.eot');
src: url('#{$font-path}.eot?#iefix') format('embedded-opentype'),
url('#{$font-path}.woff2') format('woff2'),
url('#{$font-path}.woff') format('woff'),
url('#{$font-path}.ttf') format('truetype');
}
@if $support-required=='recent' {
src: url('#{$font-path}.woff2') format('woff2'),
url('#{$font-path}.woff') format('woff'),
url('#{$font-path}.ttf') format('truetype');
}
@if $support-required=='modern' {
src: url('#{$font-path}.woff2') format('woff2'),
url('#{$font-path}.woff') format('woff');
}
}
@if $support-required !='oldie' and $support-required !='recent' and $support-required !='modern' {
@error 'Invalid support-required value. Must be "oldie"==>IE8 and above/ Android native browser 4+/ Safari 4.3 OR "recent"==>IE9+/ Android native browser 4.0+/ Safari 4.3+ OR "modern"==>IE9+/ Android native browser 4.4+/ Safari 5.1+';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment