douchuang4402 2017-01-18 03:18
浏览 205

laravel - 链接到自定义字体

I have already asked and played around with this question on Laravel discussions here (https://laracasts.com/discuss/channels/code-review/linking-to-custom-font-file-from-a-stylesheet-inside-a-blade-template). moving the file back to the stylesheet and removing the asset in the link the did not. I am trying to import custom fonts into my website, but because of Laravel's router, I can't directly link to the font files in my CSS. how can I get my custom fonts to display in the browser? So far, this dosent work:

 @font-face { font-family: NexaBold; src: url('{!! asset('build/fonts/NexaBold.otf') !!}'); }

@font-face { font-family: NexaLight; src: url('{!! asset('build/fonts/NexaLight.otf') !!}'); }

@font-face { font-family: OpenSans; src: url('{!! asset('build/fontsOpenSans-Regular.ttf') !!}'); }

I tried replacing asset with public_path but that didn't work either. How do I get my fonts to display using the Laravel blade engine?

  • 写回答

1条回答 默认 最新

  • dps43378 2019-01-22 16:32
    关注

    You can put your fonts in this directory /storage/app/public/fonts, so they can be accessible from the frontend:

    This is how you can import them:

    @font-face {
            font-family:'NexaBold';
            src: url('/fonts/NexaBold.otf') format('otf');
            font-style: normal;
            font-weight: normal;
        }
    @font-face {
            font-family:'NexaLight';
            src: url('/fonts/NexaLight.otf') format('otf');
            font-style: normal;
            font-weight: normal;
        }
    @font-face {
            font-family:'OpenSans';
            src: url('/fonts/OpenSans-Regular.ttf') format('ttf');
            font-style: normal;
            font-weight: normal;
        }
    

    Than to style some elements:

    body{
        font-family: NexaLight,Arial,Helvetica,sans-serif;
    }
    h1, h2{
        font-family: NexaBold,Arial,Helvetica,sans-serif;
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器