布局和其他刀片中的 Laravel 字体
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23265881/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel Font face in layout and other blade
提问by Racoon
I have layout view with one css and two fonts in header, and yield header for another blade views:
我在标题中有一个 css 和两种字体的布局视图,并为另一个刀片视图生成标题:
{{ HTML::style('css/style1.css') }}
@yield('header')
<style type="text/css">@font-face { font-family:nav-font; src: url('font/brandon_grotesque_medium.ttf'); }</style>
<style type="text/css">@font-face { font-family:Noto-Sans; src: url('font/NotoSans-Bold.ttf'); }</style>
They both work fine in in this layout view. But i have another view:
它们在此布局视图中都可以正常工作。但我有另一个看法:
@extends('layout')
@section('header')
{{ HTML::style('css/posts/style2.css') }}
@stop
@section('content')
My content here.
@stop
style2 Css works fine in my second view, but fonts are missing. I have tried to put font scripts in header section in my second view, but still nothing. What can be the problem?
style2 Css 在我的第二个视图中工作正常,但缺少字体。我试图在我的第二个视图中将字体脚本放在标题部分,但仍然没有。可能是什么问题?
回答by lagbox
You could use the asset()
Helperfor an example.
您可以使用asset()
Helper作为示例。
<style type="text/css">@font-face {
font-family:nav-font; src: url('{{ asset('font/brandon_grotesque_medium.ttf') }}');
}</style>
<style type="text/css">@font-face {
font-family:Noto-Sans; src: url('{{ asset('font/NotoSans-Bold.ttf') }}');
}</style>
This type of approach will remove the need for the relative pathing as it will resolve to an absolute Url. This will remove the "relative sorcery" as zwacky had mentioned in the comments.
这种类型的方法将消除对相对路径的需要,因为它将解析为绝对 URL。这将删除 zwacky 在评论中提到的“相对巫术”。