LoginSignup
15
14

More than 5 years have passed since last update.

RailsでCustom Web fontを使う

Posted at

icomoonなどのCustom web fontをrailsで使う方法です。

Web fontの配置

|-app/
|---assets/
|-----fonts/
|-----images/
|-----javascripts/
|-----stylesheets/

こんな感じで配置。

asset のpathに追加

app/config/initializer/assets.rb

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

scssの編集

@font-face {
  font-family:'icofonts';
  src:font-url('icofonts.eot');
  src:font-url('icofonts.eot?#iefix') format('embedded-opentype'),

  ...
} 

ポイントはcssでいうところのsrc:url()src:font-url()にすることです。

あとはunicornとかの再起動すれば反映されます。

参考

Custom Web Fonts and the Rails Asset Pipeline

15
14
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
15
14