简体   繁体   English

无法更改 main.css 中的字体系列

[英]Can't change font-family in main.css

Currently using Django with bootstrap 4. For whatever reason, I cannot get the font-family to change through my main.css file.目前使用带有 bootstrap 4 的 Django。无论出于何种原因,我都无法通过我的 main.css 文件更改字体系列。 I can change other attributes, but font does not seem to work.我可以更改其他属性,但字体似乎不起作用。

If I change the font-family in my other files, it works.如果我更改其他文件中的字体系列,它会起作用。 I just cannot change it through my main.css.我只是无法通过我的 main.css 更改它。

What am I doing wrong?我究竟做错了什么?

base.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;
}

You either have 2 options, create a style tag in the head tag or select everything instead of body in main.css.您有 2 个选项,在 head 标签中创建一个样式标签,或者在 main.css 中选择所有内容而不是 body。 Example:例子:

base.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>
...

or要么

main.css主文件

* {
    font-family: "Times New Roman", Georgia, serif !important;
}

Why don't you try:你为什么不试试:

body style="font-family:Times New Roman, Georgia,serif !important" Directly in the HTML code body style="font-family:Times New Roman, Georgia,serif !important" 直接在 HTML 代码中

Also, you can try putting the main.css file in the same folder as the HTML file and check if that works.此外,您可以尝试将 main.css 文件与 HTML 文件放在同一文件夹中,然后检查是否有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM