【发布时间】: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:,例如<link href="https://fonts.googleapis.com/css?family=Bangers&display=swap" rel="stylesheet" type="text/css"> -
@MikePoole 不是它没有。 “隐式协议”,developer.mozilla.org/en-US/docs/Learn/Common_questions/…
-
适用于给定的 URL,并应用显示的样式 - jsfiddle.net/0L5wqfsd
-
@04FS 明白了,但我不知道为什么人们会在旧浏览器不支持的情况下选择使用隐式协议。当然,我们应该为最广泛的基础进行编码。
-
@MikePoole 如果我们谈论的是 IE
标签: html css django django-templates google-fonts