Skip to content

Instantly share code, notes, and snippets.

@textandhypertext
Created March 2, 2012 12:48
Show Gist options
  • Save textandhypertext/1958208 to your computer and use it in GitHub Desktop.
Save textandhypertext/1958208 to your computer and use it in GitHub Desktop.
Sass mixin for @font-face with styles and weights
=font-face($family, $style, $weight)
$prefix = "'type/" +$family + $style + $weight
@font-face
font:
family: $family
style: $style
weight: $weight
src: url($prefix + ".eot?#iefix'") format('embedded-opentype')
src: url($prefix + ".woff'" ) format('woff')
src: url($prefix + ".ttf'") format('truetype')
src: url($prefix + ".svg#svg" + $family + $style + $weight + "'") format('svg')
@textandhypertext
Copy link
Author

Sass mixin for @font-face. This revision is up-to-date with @font-face syntax and accommodates font families with additional weights and styles.

In order for it to work, rename the font files so that the style and weight appear in the filename as they would appear in the compiled CSS, e.g. "MyFontbolditalic". The obnoxious thing is that the regular style would have to be "MyFontnormalnormal", otherwise you'd have to write a mixin for every style and weight combination. If you happen to know a way around this, please let me know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment