在 Django 中使用自定义字体 Css
Using custom font in django Css
我正在尝试在我的 Django 应用程序中使用自定义字体。
以下是我的 base.html:
中的相关行
{% load static %}
<link rel="stylesheet" type="text/css" href="{% static 'recipebook/style.css' %}">
这是我的 css 文件:
@font-face {
font-family: "FiraCode-Retina";
src: url("fonts/FiraCode-Retina.ttf") format("truetype");
}
body {
margin: 0px;
background-color: aliceblue;
}
.banner {
border: 1px solid rgb(50, 50, 60);
height: 75px;
}
.headnav {
border: 1px solid rgb(50, 50, 60);
height: 50px;
}
main {
display: flex;
height: 800px;
}
.navpanel {
border: 1px solid rgb(50, 50, 60);
flex-grow: 1;
}
.mainpanel {
border: 1px solid rgb(50, 50, 60);
flex-grow: 4;
}
.smartpanel {
border: 1px solid rgb(50, 50, 60);
flex-grow: 1;
}
.footerbar {
border: 1px solid rgb(50, 50, 60);
height: 50px;
}
这是我的文件结构:
我的 CSS 正在为字体工作 except。我缺少哪些步骤才能使其正常工作?
问题是,您从未将加载的字体分配给任何元素。你必须像
一样添加它
body {
font-family: "FiraCode-Retina", sans-serif;
margin: 0px;
background-color: aliceblue;
}
只有@font-face声明是不够的。
我正在尝试在我的 Django 应用程序中使用自定义字体。
以下是我的 base.html:
中的相关行{% load static %}
<link rel="stylesheet" type="text/css" href="{% static 'recipebook/style.css' %}">
这是我的 css 文件:
@font-face {
font-family: "FiraCode-Retina";
src: url("fonts/FiraCode-Retina.ttf") format("truetype");
}
body {
margin: 0px;
background-color: aliceblue;
}
.banner {
border: 1px solid rgb(50, 50, 60);
height: 75px;
}
.headnav {
border: 1px solid rgb(50, 50, 60);
height: 50px;
}
main {
display: flex;
height: 800px;
}
.navpanel {
border: 1px solid rgb(50, 50, 60);
flex-grow: 1;
}
.mainpanel {
border: 1px solid rgb(50, 50, 60);
flex-grow: 4;
}
.smartpanel {
border: 1px solid rgb(50, 50, 60);
flex-grow: 1;
}
.footerbar {
border: 1px solid rgb(50, 50, 60);
height: 50px;
}
这是我的文件结构:
我的 CSS 正在为字体工作 except。我缺少哪些步骤才能使其正常工作?
问题是,您从未将加载的字体分配给任何元素。你必须像
一样添加它body {
font-family: "FiraCode-Retina", sans-serif;
margin: 0px;
background-color: aliceblue;
}
只有@font-face声明是不够的。