我在哪里放置自定义字体在Laravel 5? [英] Where do I place custom fonts in Laravel 5?

查看:250
本文介绍了我在哪里放置自定义字体在Laravel 5?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

完全初学Laravel 5,并尝试在头文件中使用此代码导入自定义字体:

 < style> 
@ font-face {
font-family:'Conv_OptimusPrinceps';
src:url('fonts / OptimusPrinceps.eot'); (''☺'),url('字体/ OptimusPrinceps.woff')格式('woff'),url('字体/ OptimusPrinceps.ttf')格式('truetype'),url('字体/ OptimusPrinceps.svg')格式('svg');
font-weight:normal;
font-style:normal;

$ / code $ / pre



和在我的variables.scss中调用它。目前我的字体存储在我的公共目录中:

pre $ public $ f $ b $ public / fonts / OptimusPrinceps .tff

出于某种原因,此警告出现在我的开发工具中

 未能解码下载的字体:http:// localhost:3000 / fonts / OptimusPrinceps.tff 
OTS解析错误:无效版本标记

而我的字体加载不正确。

/ public / 中。您可以使用Laravel助手函数 public_path 为其构建完整的URL。

https://laravel.com/docs/5.2/helpers#method-public-path

例如,如果您将字体放在 /public/fonts/OptimusPrinceps.tff (您已经完成)中,您可以通过以下两种方式之一访问它





$ p $ < style type =text / CSS>
@ font-face {
font-family:OptimusPrinceps;
src:url('{{public_path('fonts / OptimusPrinceps.tff')}}');
}
< / style>

在CSS中包含:

  @ font-face {
font-family:OptimusPrinceps;
src:url('/ fonts / OptimusPrinceps.tff');



$ b $ p
$ b

在第二个例子中,你真的不需要任何Laravel的魔法。只要引用路径,使其指向正确的目录。



值得注意的是,这与Bootstrap和SCSS一起使用。我通常把字体放在 / public / static / fonts / 中。


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.

解决方案

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/.

这篇关于我在哪里放置自定义字体在Laravel 5?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆