html - 为什么我的网站没有使用我指定的字体?无法访问字体?

标签 html css ruby-on-rails ruby-on-rails-4 fonts

我正在使用 Rails 并按如下方式指定了我的字体:

#Application.html.erb includes in the head:
<link href='http://fonts.googleapis.com/css?family=Indie+Flower' rel='stylesheet' type='text/css'>

#One of the stylesheets includes:
body{ font-family: 'Indie Flower', sans-serif; }

我也在使用 Bootstrap gem(它可能覆盖了上面的内容?)。

但是,在开发服务器上,我的站点不使用我指定的字体。我认为它是 Helvetica。我做错了什么?

我还与检查员核实过,它提供了以下信息:

  • body 表示font-family: "Indie Flower",sans-serif;
  • 例如,对于下一个 div,它表示相同。
  • div 中的 h3 表示 font-family: inherit;
  • 对于 div 中的 h5 也是如此。
  • div 中的 p 显示 font-family: "Indie Flower",sans-serif;

所以您会认为字体确实是 Indie Flower,但事实并非如此。我还使用另一种字体对其进行了检查,所有文本再次显示为我认为是 Helvetica 而不是我指定的字体。

我做错了什么?


更新: application.html.erb:

<!DOCTYPE html>
<html>
<head>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track' => true %>
  <link href='http://fonts.googleapis.com/css?family=Indie+Flower' rel='stylesheet' type='text/css'>
  <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
  <%= csrf_meta_tags %>
  <%= render 'shared/shim' %>
</head>
<body>
  <%= yield %>
</body>
</html>

我也尝试过将字体向上移动到样式表上方,但这没有任何区别。

application.css:

/*
 * This is a manifest file that'll be compiled into application.css, which will include all the files
 * listed below.
 *
 * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
 * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
 *
 * You're free to add application-wide styles to this file and they'll appear at the bottom of the
 * compiled file so the styles you add here take precedence over styles defined in any styles
 * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
 * file per style scope.
 *
 *= require bootstrap-datepicker3
 *= require_tree .
 *= require_self
 */

更新 2:从 application.html.erb 中删除字体确认它没有显示正确的字体。在检查器中,它指定了正确的字体。但是,它实际上并没有使用该字体。同样,我可以在 css 中指定一个带有一些随机名称的字体系列,它显示的字体与现在相同。

因此,我的印象是它在 css 中正确指定,但应用程序无法访问该字体,因此会退回到 verdana。也许应用程序无法加载字体?但为什么会这样或者为什么它不能访问字体?我尝试了不同的谷歌字体,并相信它们的来源每次都在 application.html.erb 中正确指定。怎么办?

最佳答案

试试这个:

body{
    font-family: 'Indie Flower', cursive;
}

关于html - 为什么我的网站没有使用我指定的字体?无法访问字体?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30821862/

相关文章:

javascript - 同一域的访问控制允许来源?

javascript - 如何删除并重新添加在 div 中播放的 twilio 视频轨道?

html - 无法将文字放在图像上

html - 我的图标没有向右浮动

html - 如何指定 xpath 以从有条件的 parent 和 child 那里获取数据?

asp.net - ASP.NET 中的快捷栏

css - 改进生成的 ASP.Net MVC 表单 View 的布局

ruby-on-rails - 为什么即使我允许,Rails 仍然告诉我未经允许的参数?

ruby-on-rails - 通过sql查找中的参数sql查询

mysql - 尝试部署 Rails 应用程序时获取 ActiveRecord::AdapterNotSpecified: 'old_production' 数据库未配置