Skip to content

Instantly share code, notes, and snippets.

@rianrainey
Created September 23, 2013 15:54
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save rianrainey/6672657 to your computer and use it in GitHub Desktop.
Save rianrainey/6672657 to your computer and use it in GitHub Desktop.
Use Bourbon's mixin, @font-face, to easily include Fonts into your project.
/* @include font-face(SourceSansPro, '/fonts/Source_Sans_Pro/SourceSansPro-Regular'); */
@font-face {
font-family: SourceSansPro;
font-weight: normal;
font-style: normal;
src: url(/assets/Source_Sans_Pro/SourceSansPro-Regular.eot);
src: url(/assets/Source_Sans_Pro/SourceSansPro-Regular.eot?#iefix) format("embedded-opentype"),
url(/assets/Source_Sans_Pro/SourceSansPro-Regular.woff) format("woff"),
url(/assets/Source_Sans_Pro/SourceSansPro-Regular.ttf) format("truetype"),
url(/assets/Source_Sans_Pro/SourceSansPro-Regular.svg#SourceSansPro) format("svg");
}
// Taken from: https://github.com/thoughtbot/bourbon/blob/master/app/assets/stylesheets/css3/_font-face.scss
// Order of the includes matters, and it is: normal, bold, italic, bold+italic.
@mixin font-face($font-family, $file-path, $weight: normal, $style: normal, $asset-pipeline: false ) {
@font-face {
font-family: $font-family;
font-weight: $weight;
font-style: $style;
@if $asset-pipeline == true {
src: font-url('#{$file-path}.eot');
src: font-url('#{$file-path}.eot?#iefix') format('embedded-opentype'),
font-url('#{$file-path}.woff') format('woff'),
font-url('#{$file-path}.ttf') format('truetype'),
font-url('#{$file-path}.svg##{$font-family}') format('svg');
} @else {
src: url('#{$file-path}.eot');
src: url('#{$file-path}.eot?#iefix') format('embedded-opentype'),
url('#{$file-path}.woff') format('woff'),
url('#{$file-path}.ttf') format('truetype'),
url('#{$file-path}.svg##{$font-family}') format('svg');
}
}
}
/*
* Taken from: http://bourbon.io/docs/#font-face
*/
// Wordpress/Drupal/etc ways to use
@include font-face(SourceSansPro, '/fonts/Source_Sans_Pro/SourceSansPro-Regular');
@include font-face(SourceSansPro, '/fonts/Source_Sans_Pro/SourceSansPro-Bold', bold);
@include font-face(SourceSansPro, '/fonts/Source_Sans_Pro/SourceSansPro-Italic', normal, italic);
// Rails asset-pipeline - place fonts in app/assets/fonts/. Remember to restart
// you server
@include font-face(SourceSansPro, 'Source_Sans_Pro/SourceSansPro-Regular', normal, $asset-pipeline: true);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment