加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – 在Ruby on Rails 3.2应用程序中集成googlefont

发布时间:2020-12-17 02:37:42 所属栏目:百科 来源:网络整理
导读:我必须在一个Rails应用程序中使用Google的字体.普通的 HTML代码定义了googlefonts用法,如下所示: link href='http://fonts.googleapis.com/css?family=PT+Sans:400,700,400italic' rel='stylesheet' type='text/css' 我试图在alpplication.html.erb中添加相
我必须在一个Rails应用程序中使用Google的字体.普通的 HTML代码定义了googlefonts用法,如下所示:

<link href='http://fonts.googleapis.com/css?family=PT+Sans:400,700,400italic' rel='stylesheet' type='text/css'>

我试图在alpplication.html.erb中添加相同的行,但它不起作用.然后我将@ font-face定义(从link-href指向的位置)解压缩到一个单独的css.scss文件中,并将该文件包含在我的manifest css文件中:

#googlefonts.css.scss
@font-face {
font-family: 'PT Sans';
font-style: italic;
font-weight: 400;
src: local('PT Sans Italic'),local('PTSans-Italic'),url(http://themes.googleusercontent.com/static/fonts/ptsans/v4/xxxx.woff) format('woff');

}

#application.css

   *= require googlefonts
   *= require_tree .

它没有再发生过.

拜托,帮我解决这个难题.在Rails 3应用程序中使用Google托管的字体的最佳做法是什么?

编辑:这是我的CSS,指的是@ font-face定义:

#styles.css.scss
body{
font-family: "PT Sans",Arial,Helvetica,sans-serif;
font-size:13px;
line-height:25px;
text-shadow:none !important;
color:#444;
}

解决方法

使用您的示例代码,以下工作对我来说很好:

# stick this inside the head section of application.html.erb 
<link href='http://fonts.googleapis.com/css?family=PT+Sans:400,400italic' rel='stylesheet' type='text/css'>

# stick this in your css file:
body{
  font-family: "PT Sans",sans-serif;
}

这就是你所需要的,它运作得很好.我建议放弃googlefonts.css.scss文件,除非你有你想要提供的字体的本地副本.链接谷歌为您提供实际处理该代码,无论如何,see for yourself

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读