【发布时间】:2021-03-12 12:50:15
【问题描述】:
所以我真的是编程新手,但我无法理解为什么我的文本没有以自定义字体显示。它显示白色斜体文本,但我无法让字体工作。感谢您的帮助!
<html>
<head>
<title>Webpage</title>
<style>
@font-face
{
font-family: 'my font';
src: url(C:\Users\theuser\Font\My Custom Font.woff2) format('woff2'),
url(C:\Users\theuser\Font\My Custom Font.ttf) format('truetype'),
}
h2
{
font-family: 'my font';
color: white;
font-style: italic;
}
</style>
<h2>Header text</h2>
</head>
<body>
<p style="color:white;">Font testing</p>
<body bgcolor="#000000">
</body>
</html>```
【问题讨论】:
-
首先,字体的路径:它不应该是以 C:\ 开头的东西,因为这在 linux/macOS 上不起作用,相反你需要一个以 ./ 开头的 URL或/(分别是http服务器的这个文件夹或根文件夹)。我还强烈建议您不要使用服务器上的字体,而是使用 google fonts 中的字体,它非常易于使用并且对我来说效果很好。
-
谢谢!我会试一试谷歌字体,但到目前为止我的字体似乎正在工作,所以我想我不会篡改它。不过还是谢谢!