Skip to content

Instantly share code, notes, and snippets.

@rey
Forked from rianrainey/mixin-ouput.css
Created February 25, 2016 15:18
Show Gist options
  • Save rey/ed2c5704d580f8ed9577 to your computer and use it in GitHub Desktop.
Save rey/ed2c5704d580f8ed9577 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