html - 字体不会从 CSS 文件更改
问题描述
目前使用带有引导程序 4 的 Django。无论出于何种原因,我都无法通过我的 main.css 文件更改字体系列。我可以更改其他属性,但字体似乎不起作用。
如果我更改其他文件中的字体系列,它会起作用。我只是无法通过我的 main.css 更改它。
我究竟做错了什么?
索引.html
{% load static %}
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<link rel="stylesheet" href="{% static 'css/main.css' %}">
...
main.css
body {
font-family: "Times New Roman", Georgia, serif !important;
}
解决方案
您要么有 2 个选项,要么在 head 标签中创建样式标签,要么在 main.css 中选择所有内容而不是 body。例子:
索引.html
{% load static %}
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<link rel="stylesheet" href="{% static 'css/main.css' %}">
<style>
* {
font-family: "Times New Roman", Georgia, serif !important;
}
</style>
...
或者
main.css
* {
font-family: "Times New Roman", Georgia, serif !important;
}
推荐阅读
- sql-server - 键入字符串作为参数输入,返回错误消息“将数据类型 nvarchar 转换为日期时间时出错。”
- ios - 多线程上的核心数据操作导致插入但没有获取
- powershell - PowerShell Get-FileHash 的管道和圆括号有什么区别?
- python - 如何覆盖 str 子类的“按 % 格式化”的方法?
- python - 如何在不保留大量值的情况下获取 Python 中不同值的计数
- php - 如何访问嵌套 JSON 的某些部分?
- php - 如何让 PHP 理解 * 或 * 一个数组或函数参数的 splat 运算符(3 点 ...)?
- sql - 允许空 SET 语句(没有 SET 选项分配)
- python - ImportError:在执行 python3 manage.py 迁移时无法导入名称“memoize”
- ios - 如何转换 MyResult
到我的数据?