How to use fonts in Rails 4

前端 未结 9 1550
别那么骄傲
别那么骄傲 2020-12-08 02:03

I have a Rails 4 application and I am trying to use a custom font.

I have followed many tutorials on this and somehow it\'s just not working for my application.

<
9条回答
  •  無奈伤痛
    2020-12-08 02:28

    Please do not hardcode your font directory since the location is dynamic.

    Just like there are built-in helpers for images there is are also built-in helpers for fonts: http://api.rubyonrails.org/classes/ActionView/Helpers/AssetUrlHelper.html#method-i-font_url

    Example:

    @font-face {
        font-family: 'QuicksandOTF';
        src: font_url('Quicksand-Regular.otf') format('opentype');
        font-weight: normal;
        font-style: normal;
    }
    

提交回复
热议问题