如何将字体上载到网页(需要服务器)? [英] How do you upload a font to your webpage (is the server needed)?

查看:104
本文介绍了如何将字体上载到网页(需要服务器)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将自定义字体上传到我的网站,但是一直失败,并且我不确定是否需要在服务器中添加路由才能使其正常工作(我正在使用python flask).

I am trying to upload a custom font to my site, but keep failing and I am not sure if I need to add routing in my server for it to work (I am using python flask).

在启动服务器之前,字体在我计算机的 static/fonts/Sofia_Handwriting.otf 中.

The font is in static/fonts/Sofia_Handwritten.otf in my computer, before launching the server.

我尝试访问它的方式是:

And the way I am trying to access it is:

@font-face {
    font-family: "Sofia_Handwritten";
    src: url("fonts/Sofia_Handwritten.otf");
}

#greeter {
    font-size: 50px;
    font-family: 'Sofia_Handwritten';
}

但是无论什么字体都不会显示.

But no matter what the font doesn't display.

服务器回复200,所以发现还可以.

The server replies with 200, so it;s finding it just fine.

错误在于文件本身.

推荐答案

@ font-face应该位于您的 static/fonts/Sofia_Handwriting.css 中.这样做之后,您转到HTML并添加如下内容:

The @font-face should be in your static/fonts/Sofia_Handwritten.css. After doing so, you go to your HTML and add something like this:

<link href="static/fonts/Sofia_Handwritten.css" rel="stylesheet">

然后您就可以使用您的字体.

and then you will be able to use your font.

这篇关于如何将字体上载到网页(需要服务器)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆