Siv*_*iva 8 css fonts ruby-on-rails ruby-on-rails-7
在开发模式下,存在自定义字体(Raleway),但不会反映在暂存环境中。我将我的应用程序部署到 Heroku。
在application.rb中添加以下命令
config.assets.paths << Rails.root.join('app', 'assets', 'fonts')
Run Code Online (Sandbox Code Playgroud)
在 application.bootstrap.scss 中添加了 font-family
@font-face {
font-family: 'raleway-regular';
font-style: normal;
font-weight: 400;
src: font-url('raleway-regular.ttf') format('truetype');
}
@font-face {
font-family: 'raleway-semibold';
src: font-url('raleway-semibold.ttf') format('truetype');
}
@font-face {
font-family: 'raleway-medium';
src: font-url('raleway-Medium.ttf') format('truetype');
}
Run Code Online (Sandbox Code Playgroud)
字体文件可在my_app/app/assets/fonts目录中找到。
我使用命令创建了 Railsrails new my_app --javascript esbuild --css bootstrap --database postgresql
导轨版本 7
小智 6
尝试使用url而不是font-url. 这个对我有用。与scss和文件夹配置相同。
@font-face {
font-family: 'font-name';
font-style: normal;
font-weight: 400;
font-display: swap;
src: url("font-name.ttf") format('truetype');
}
Run Code Online (Sandbox Code Playgroud)
Rails 创建自己的字体路径
/assets/font-name-afb238caf5f2396b697d84a32556090b0851e382692f617c6aeaac79e02971a0.ttf
Run Code Online (Sandbox Code Playgroud)