Complete beginner to Laravel 5 and trying to import custom fonts using this code in my header:
<style> @font-face { font-family: 'Conv_OptimusPrinceps'; src: url('fonts/OptimusPrinceps.eot'); src: local('☺'), url('fonts/OptimusPrinceps.woff') format('woff'), url('fonts/OptimusPrinceps.ttf') format('truetype'), url('fonts/OptimusPrinceps.svg') format('svg'); font-weight: normal; font-style: normal; }
and calling it in my variables.scss. Currently my fonts are stored in my public directory:
public/fonts/OptimusPrinceps.woff public/fonts/OptimusPrinceps.tff etc.
For some reason this warning appears in my dev tools
Failed to decode downloaded font: http://localhost:3000/fonts/OptimusPrinceps.tff OTS parsing error: invalid version tag
And my font doesn't load correctly.
All fonts are stored in the C:\Windows\Fonts folder. You can also add fonts by simply dragging font files from the extracted files folder into this folder. Windows will automatically install them. If you want to see what a font looks like, open the Fonts folder, right-click the font file, and then click Preview.
First, choose your fonts on fonts.google.com and grab the CSS URL. Next, install the package and publish the config file. Paste the CSS URL in the default font set.
Place anything that the client browser should access into /public/
. You can use the Laravel helper function public_path
to build full URLs for it.
https://laravel.com/docs/5.2/helpers#method-public-path
For instance, if you put your font in /public/fonts/OptimusPrinceps.tff
(which you've done), you can access it one of two ways.
In Blade:
<style type="text/css"> @font-face { font-family: OptimusPrinceps; src: url('{{ public_path('fonts/OptimusPrinceps.tff') }}'); } </style>
In CSS includes:
@font-face { font-family: OptimusPrinceps; src: url('/fonts/OptimusPrinceps.tff'); }
In the second example, you don't need any Laravel magic, really. Just reference the path absolutely so that it points to the correct directory.
Worth noting that this works with Bootstrap and SCSS. I usually put fonts in /public/static/fonts/
.
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