【问题标题】:Google font not displaying谷歌字体不显示
【发布时间】:2020-01-17 22:51:49
【问题描述】:

我正在尝试将 Google 字体从 css 加载到我的应用程序的 html 模板中。无法让“上传 schtuff”假设 Bangers 字体。这是base.html:

{% load static %}
   <!doctype html>
  <html>
  <title>{% block title %}Upload Schtuff{% endblock %}</title>
       <head>
            <link href="//fonts.googleapis.com/css?family=Bangers&display=swap" rel="stylesheet" type="text/css">
            <link rel="stylesheet" href="{% static 'css/style.css' %}">
            <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
            <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css">
      </head>
      <body>
          <div>
            <h1><a href="/">Upload schtuff </a></h1>
            </div>
      </body>
</html>

Here's the static/uploader/style.css:
'''
h1 a, h2 a
{
	color: #714D91;
	font-family: 'Bangers', cursive;
}
'''

I've also tried importing the font to the style sheet with 
@import url('https://fonts.googleapis.com/css?family=Bangers&display=swap');

Also tried importing it to the .html file
<style>
@import url('https://fonts.googleapis.com/css?family=Bangers&display=swap');
</style>

这一定是我的链接href行,对吧? 提前致谢!

【问题讨论】:

  • 链接需要以协议开头,即https:,例如&lt;link href="https://fonts.googleapis.com/css?family=Bangers&amp;display=swap" rel="stylesheet" type="text/css"&gt;
  • @MikePoole 不是它没有。 “隐式协议”,developer.mozilla.org/en-US/docs/Learn/Common_questions/…
  • 适用于给定的 URL,并应用显示的样式 - jsfiddle.net/0L5wqfsd
  • @04FS 明白了,但我不知道为什么人们会在旧浏览器不支持的情况下选择使用隐式协议。当然,我们应该为最广泛的基础进行编码。
  • @MikePoole 如果我们谈论的是 IE

标签: html css django django-templates google-fonts


【解决方案1】:

好的,我开始工作了!这是我第一次添加多个 Css 文件......我在我的 settings.py 文件中错过了这个

STATICFILES_DIRS = [os.path.join(BASE_DIR, "static")]

大声笑,感谢您在我解决自己的问题时成为一个优秀的社区并支持我!

【讨论】:

    猜你喜欢
    • 2013-04-20
    • 2013-01-16
    • 2018-07-11
    • 1970-01-01
    • 2014-12-17
    • 2017-11-08
    • 1970-01-01
    • 2019-09-07
    • 1970-01-01
    相关资源
    最近更新 更多