Skip to content

Instantly share code, notes, and snippets.

@JodiWarren
Last active June 30, 2016 09:10
Show Gist options
  • Select an option

  • Save JodiWarren/574247831bfad0eb0e3600f1be25a28a to your computer and use it in GitHub Desktop.

Select an option

Save JodiWarren/574247831bfad0eb0e3600f1be25a28a to your computer and use it in GitHub Desktop.
Quick and easy mixin for adding new fonts in a consistent manner.
////
/// @author Jodi Warren for JH
/// @group _fonts
////
/// Add a new @font-face font with consistent markup. All file types should
/// be provided with the same file name, obviously bar the extension.
/// If you wish to use multiple weights/styles of the same font family, simply
/// provide them with the same family name, and specify the weight and style.
///
/// @example @include addFont('Gill Sans', '../fonts/gill-sans/gill-sans-regular', 400, normal);
///
/// @param $family {string} The font family name that you wish to use in CSS.
/// @param $pathWithoutFileType {string} The path to the file.
/// @param $weight {number} The CSS weight of this font file.
/// @param $style {string} The style of this font file. Should be normal, italic, or oblique.
///
/// @output A @font-face block
@mixin addFont($family, $pathWithoutFileType, $weight: 400, $style: normal) {
@font-face {
font-family: $family;
src: url('#{$pathWithoutFileType}.eot');
src: url('#{$pathWithoutFileType}.eot?#iefix') format('embedded-opentype'), url('#{$pathWithoutFileType}.woff2') format('woff2'), url('#{$pathWithoutFileType}.woff') format('woff'), url('#{$pathWithoutFileType}.ttf') format('truetype');
font-style: $style;
font-weight: $weight;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment