2018年12月8日 星期六

在 Rails 使用 custom font


參考 https://coderwall.com/p/v5c8kq/web-fonts-and-rails-asset-pipeline 把檔案放到 `app/assets/fonts` 裡面

然後在 `application.scss` 裡加上

```scss

@font-face {
  font-family: 'Calibre';
  src: font-url('calibre/regular/Calibre-Regular.otf')  format('opentype'),
       font-url('calibre/regular/Calibre-Regular.woff') format('woff'),
       font-url('calibre/regular/Calibre-Regular.ttf')  format('truetype'),
       font-url('calibre/regular/Calibre-Regular.svg#Calibre-Regular') format('svg');
  font-weight: normal;
  font-style: normal;
}

@font-face {
  font-family: 'Calibre';
  src: font-url('calibre/medium/Calibre-Semibold.woff2') format('woff');\
  font-weight: bold;
  font-style: bold;
}

b, strong {
  font-weight:bold
}

h1, h2, h3, h4, h5, h6 {
  font-weight:bold
}

```

這樣就行

(font-face 可以放在別的 file 再 import 也可以)




https://coderwall.com/p/v5c8kq/web-fonts-and-rails-asset-pipeline
https://github.com/nicotaing/chloepark/tree/master/themes/park/source/fonts/calibre/regular

沒有留言:

張貼留言