1. 下载字体文件(.woff)
2. 在scss文件中引入字体
assets/stylesheets/application/font_oswald.scss
@font-face {
font-family: 'Oswald';
src: asset_url('Oswald-Bold.ttf') format('ttf'),
asset_url('Oswald-Bold.woff') format('woff');
font-weight: 700;
font-style: none;
font-display: swap;
}
3. 在index.scss导入此文件
assets/stylesheets/application/index.scss
@import "./font_oswald.scss";
4. 在其他scss页面添加使用此字体的样式class
assets/stylesheets/application/other.scss
.font-oswald {
font-family: 'Oswald';
}
5. 具体页面使用
page.html.erb
<h1 class="font-oswald">title</h1>