How to use fonts in Rails 4

前端 未结 9 1543
别那么骄傲
别那么骄傲 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:33

    In Rails 4, there is a helper to set the path for the fonts.

    If you have the font in /assets/fonts or vendor/assets/fonts, Rails 4 will find them! To take advantage of this, in the Bootstrap CSS file change the @font_face call to

    @font-face {
      font-family: 'Glyphicons Halflings';
      src: font-url('glyphicons-halflings-regular.eot');
      src: font-url('glyphicons-halflings-regular.eot?#iefix') format('embedded-opentype'), 
           font-url('glyphicons-halflings-regular.woff') format('woff'), 
           font-url('glyphicons-halflings-regular.ttf') format('truetype'), 
           font-url('glyphicons-halflings-regular.svg#glyphicons_halflingsregular') format('svg');
    }
    

    Note that there is no folder specification in front the font files. This is completed by the rails helper.

提交回复
热议问题