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>
文章详细介绍了如何下载WOFF字体文件,然后在SCSS中通过@font-face规则引入,设置字体权重和样式。接着在主SCSS文件导入该规则,并创建样式类在其他页面中使用该自定义字体。

315





