我正在使用 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/