Using @font-face with Rails 3.1 app?

前端 未结 7 1814
青春惊慌失措
青春惊慌失措 2020-12-02 08:23

I\'m having trouble using the following @font-face declaration to work with my Rails 3.1 app. I put the fonts in the Asset Pipeline in its own folder called \"

7条回答
  •  情话喂你
    2020-12-02 09:07

    Using Rails 4.0 (don't know if this is specific to 4, but anyway), I was only able to make it work with url(font_path('font-name.ttf')). Adding the fonts path to the assets path was not necessary either (config.assets.paths << "#{Rails.root}/app/assets/fonts").

    So, to me this is what worked:

    @font-face {
      font-family: 'ChunkFiveRegular';
      src: url(font_path('Chunkfive-webfont.eot'));
      src: url(font_path('Chunkfive-webfont.eot?#iefix')) format('embedded-opentype'),
         url(font_path('Chunkfive-webfont.woff')) format('woff'),
         url(font_path('Chunkfive-webfont.ttf')) format('truetype'),
         url(font_path('Chunkfive-webfont.svg#ChunkFiveRegular')) format('svg');
      font-weight: normal;
      font-style: normal;
    }
    

提交回复
热议问题