Using fonts with Rails asset pipeline

前端 未结 12 1608
慢半拍i
慢半拍i 2020-11-22 14:52

I have some fonts being configured in my Scss file like so:

@font-face {
  font-family: \'Icomoon\';
  src: asset-url(\'icoMoon.eot?#iefix\', font) format(\'         


        
12条回答
  •  有刺的猬
    2020-11-22 15:06

    just place your fonts inside app/assets/fonts folder and set the autoload path when app start using writing the code in application.rb

    config.assets.paths << Rails.root.join("app", "assets", "fonts") and

    then use the following code in css.

    @font-face {

     font-family: 'icomoon';
     src: asset-url('icomoon.eot');
     src: asset-url('icomoon.eot') format('embedded-opentype'),
          asset-url('icomoon.woff') format('woff'),
          asset-url('icomoon.ttf') format('truetype'),
          asset-url('icomoon.svg') format('svg');
     font-weight: normal;
     font-style: normal;
    

    }

    Give it a try.

    Thanks

提交回复
热议问题