I need to import true type font locally for my webside.
For remote fonts I'm always using
@import url('https://example');
but not sure how to import it from files.
I believe it's very simple but I wasn't able to find and good result.
Thank you
In your main SCSS compile file, import Font Awesome by adding the core styles file, @import "scss/fontawesome. scss" . Then import one or more styles.
You can use EOT (Embedded OpenType) files for Internet Explorer and either OTF (OpenType) or TTF (TrueType) for the rest. (Additional options include WOFF (Web Open Font Format) and SVG (Scalable Vector Graphics) but we will stick to more common types here.)
If you don't have a local .ttf font, go to a webfont conversion site, I like this one https://onlinefontconverter.com/
Select the output formats you need, I would recommend selecting .eot , .woff , and svg along with your .ttf for cross browser compatibility.
Then in your scss, use something like this to import all versions of that font for cross browser coverage.
Update: Just using formats woff + woff2 will have you covered for all modern browsers and devices
Don't forget to add fallback fonts just incase.
@mixin font($font-family, $font-file) {
@font-face {
font-family: $font-family;
src: url($font-file+'.eot');
src: url($font-file+'.eot?#iefix') format('embedded-opentype'),
url($font-file+'.woff') format('woff'),
url($font-file+'.ttf') format('truetype'),
url($font-file+'.svg#'+$font-family) format('svg');
font-weight: normal;
font-style: normal;
}
}
@include font('Arvo', '/htdocs/lib/fonts/Arvo');
@include font('Arvo-Bold', '/htdocs/lib/fonts/Arvo-Bold');
h1 {
font-family: Arvo-Bold, Arial-bold, arial, sans-serif;
}
<h1>Hey Look! A headline in Arvo bold!</h1>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With