向 Rails 4 添加自定义字体的官方方式? [英] Official way of adding custom fonts to Rails 4?

查看:34
本文介绍了向 Rails 4 添加自定义字体的官方方式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究如何将自定义字体添加到我的 Rails 应用程序中,例如通过在资产文件夹中添加 fonts 文件夹 - 我找不到关于如何执行此操作的官方"Rails 方式.

I'm researching how to add custom fonts to my Rails app, e.g. by adding a fonts folder in the assets folder - and I cannot find an "official" Rails way on how to do this.

是的,这里有很多关于这个问题的问题/答案,似乎都有自己的技巧.但是这样的普遍做法难道不应该归于 Rails 著名的约定优于配置"吗?

Yes, there are plenty of questions/answers here on SO about the matter, all seemingly with their own hacks. But shouldn't such a common practice go under Rails' famous "convention over configuration"?

或者如果我错过了 - 关于如何在 Rails 应用程序中组织字体的文档参考在哪里?

推荐答案

是的,给出的链接会很好地解释它,但是如果你需要另一个详细的解释,那么这里是

Yes the link given will explain it well, however if u need another detailed explanation then here it is

少数最流行的字体文件格式主要是.otf(Open Type Format) .ttf(True Type Format) .woff(Web Open Font Format)

Few of the most popular font file formats are mainly .otf(Open Type Format) .ttf(True Type Format) .woff(Web Open Font Format)

您可以将下载的字体移动到您的应用文件夹中的 app/assets/fonts/

You can move the downloaded fonts to your app folder under app/assets/fonts/

下载文件后,您需要像这样声明"您将在 css 中使用的字体

After downloading the file you need to "declare" the fonts you will be using in your css like this

@font-face {
  font-family: "Kaushan Script Regular";
  src: url(/assets/KaushanScript-Regular.otf) format("truetype");
}

  • 最后,您可以像这样在任何地方使用刚刚声明的字体系列

  • Finally you can use the font-family that you just declared wherever you want like this

    #e-registration {
      font-family: "Kaushan Script Regular";
    }
    

  • 希望这会有所帮助.

    这篇关于向 Rails 4 添加自定义字体的官方方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆