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

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

问题描述

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


$ b $是的,这里有很多关于这个问题的问题/答案,所有这些看起来都有自己的窍门。但是,这样的常见做法不应该在Rails着名的约定配置下进行么?



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

是的,给出的链接将解释得很好,但是如果你需要另一个详细的解释,然后在这里它是


  • 首先要在你的应用程序中使用自定义字体,你需要下载字体文件,可以尝试
    http://www.1001freefonts.com/



    http://www.piccsy.com/everything-design/ 并查找字体

    最常用的几种字体文件格式主要是.otf(Open Type Format).ttf(True Type Format).woff(Web打开字体格式)


  • 您可以将下载的字体移动到您的应用程序文件夹p / assets / fonts /


  • 在下载文件后,您需要声明您将在css中使用的字体,如

    b
    $ b

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

    $ / code $ / pre $
    $ li $ p $你想这样


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





    希望这有帮助。

    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.

    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"?

    Or if I've missed it - where is the documentation reference on how to organize fonts in a Rails app?

    解决方案

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

    • Firstly to use custom fonts in your app you need to download font files, you can try http://www.1001freefonts.com/

      http://www.piccsy.com/everything-design/ and look for fonts

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

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

    • 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";
      }
      

    Hope this helps.

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

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