LoginSignup
26
22

More than 5 years have passed since last update.

Railsのfontをカスタマイズ

Last updated at Posted at 2017-06-16

RailsでWebサイトとかに落ちているフォントを使いたい時用のメモです。
http://qiita.com/natsu871/items/582320d063796d005fc3 
を参考にしつつもう少し細かく解説してみました。

以下手順

①自分が取り込みたいフォントファイルをダウンロード

②app/assets/fonts 配下にダウンロードしたフォントファイルを置きます。もしfontsフォルダーが存在しなかった場合は作ってしまいましょう。

③cssファイル(又はscssファイル)に以下を追記する

例、font-familyの名前は自由に決められるので今回はBlueskyにするとします。そしてダウンロードしたフォントファイルがcustom-Bluesky-webfont.otfだった場合、、、

sample.css
@font-face {
  font-family: 'Bluesky';
  src: font-url('custom-Bluesky-webfont.otf') format('truetype');
  font-weight: normal;
  font-style: normal;
}

使い方
例、sampleクラスのh2タグに挟まれた文字に'Bluesky'を適用する

index.erb
<div class="sample">
  <h2>hello world</h2>
</div>
sample.css
.sample h2 {
  font-family: 'Bluesky';
}
26
22
1

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
26
22